Skip to content

chore: use user token for attestation commands #1900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 13, 2025

Conversation

jiparis
Copy link
Member

@jiparis jiparis commented Mar 13, 2025

This is a follow up of #1003 to pass the user token to the attestation commands if the API token hasn't been provided via env var nor command line.
I've also removed the duplicated --token flag.

The affected commands (attestations) will now prompt the user to confirm the operation, since it will be performed against the "current" organization, which might vary depending on the chainloop org set command. The confirmation can be bypassed with the -y or --yes flag

Without CHAINLOOP_TOKEN:

✗ go run app/cli/main.go att init --workflow mywf --project myproject --replace
WRN API contacted in insecure mode
This command is will run against the organization "my-org"
Please confirm to continue y/N
n
ERR command canceled by user
✗ go run app/cli/main.go att init --workflow mywf --project myproject --replace -y
WRN API contacted in insecure mode
INF Attestation initialized! now you can check its status or add materials to it
┌───────────────────────────┬──────────────────────────────────────┐
│ Initialized At            │ 13 Mar 25 17:55 UTC                  │
├───────────────────────────┼──────────────────────────────────────┤
│ Attestation ID            │ 594dfd11-4aa6-40f2-9539-2903990afea6 │
│ Organization              │ my-org                               │
│ Name                      │ mywf                                 │
│ Project                   │ myproject                            │
│ Version                   │ v0.181.0 (prerelease)                │
│ Contract                  │ myproject-mywf (revision 95)         │
│ Policy violation strategy │ ADVISORY                             │
│ Policies                  │ ------                               │
│                           │ source-commit: Ok                    │
│                           │ sbom-present: missing SBOM material  │
└───────────────────────────┴──────────────────────────────────────┘

With CHAINLOOP_TOKEN (no warning is raised):

> export CHAINLOOP_TOKEN=xxxxxxxxx
> go run app/cli/main.go att init --workflow mywf --project myproject --replace
WRN API contacted in insecure mode
INF Attestation initialized! now you can check its status or add materials to it
┌───────────────────────────┬──────────────────────────────────────┐
│ Initialized At            │ 13 Mar 25 17:58 UTC                  │
├───────────────────────────┼──────────────────────────────────────┤
│ Attestation ID            │ 4b6bed22-401a-41fe-ad0b-a4013babb36f │
│ Organization              │ my-org                               │
│ Name                      │ mywf                                 │
│ Project                   │ myproject                            │
│ Version                   │ v0.181.0 (prerelease)                │
│ Contract                  │ myproject-mywf (revision 95)         │
│ Policy violation strategy │ ADVISORY                             │
│ Policies                  │ ------                               │
│                           │ source-commit: Ok                    │
│                           │ sbom-present: missing SBOM material  │
└───────────────────────────┴──────────────────────────────────────┘

For the rest of commands, the behaviour is the expected:

> cl wf contract ls
WRN API contacted in insecure mode
WRN Both user credentials and $CHAINLOOP_TOKEN set. Ignoring $CHAINLOOP_TOKEN.
┌───────────────────┬─────────────────┬─────────────────────┬─────────────┐
│ NAME              │ LATEST REVISION │ CREATED AT          │ # WORKFLOWS │
├───────────────────┼─────────────────┼─────────────────────┼─────────────┤
│ default-contract  │               1 │ 17 Dec 24 22:08 UTC │           0 │
│ test-test         │               4 │ 04 Nov 24 12:39 UTC │           1 │
│ myproject-example │               1 │ 21 Oct 24 16:52 UTC │           1 │
│ myproj-mywf       │               1 │ 21 Oct 24 16:42 UTC │           1 │
│ myproject-mywf    │              95 │ 29 Aug 24 17:19 UTC │           1 │
│ test3             │               1 │ 29 Aug 24 17:18 UTC │           0 │
└───────────────────┴─────────────────┴─────────────────────┴─────────────┘

Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
@jiparis jiparis requested review from migmartri and javirln March 13, 2025 15:53
}

// Use the API token if the command can use it and it's provided
if _, ok := cmd.Annotations[useAPIToken]; ok && attAPIToken != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add a confirmation y/n saying that you are going to perform an attestation in org x

jiparis added 4 commits March 13, 2025 18:04
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
@jiparis jiparis merged commit d55d686 into chainloop-dev:main Mar 13, 2025
13 checks passed
@jiparis jiparis deleted the 1003-client branch March 13, 2025 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants