Skip to content

Create long-lived tokens for CI/CD/automation (or tokens for a specific duration) #3692

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

Closed
jaulz opened this issue Aug 25, 2022 · 9 comments · Fixed by #4380
Closed

Create long-lived tokens for CI/CD/automation (or tokens for a specific duration) #3692

jaulz opened this issue Aug 25, 2022 · 9 comments · Fixed by #4380
Assignees
Milestone

Comments

@jaulz
Copy link

jaulz commented Aug 25, 2022

Add a way (likely via the CLI) to generate API tokens:

  • push templates via CI
  • use the REST API/CLI in automated pipelines

Original description

I searched the issues with multiple keywords but I could not find any information on how to push template updates from Github Actions for example. Is that actually possible? So far I tried the username/password approach but that fails because it requires the user to enter the token from the browser.

@Emyrk
Copy link
Member

Emyrk commented Aug 25, 2022

We can definitely improve on this, but in the short term, the token returned by the cli-auth lasts 7 days. It will be refreshed if it's used at least once in that 7 day time period. So you can get the token from /cli-auth on your user, or some machine user you made. And put that token into your CI/CD.

You can use the token in the cli directly, and not use coder login. In github actions you can use the coder cli to upload the templates using the cli flags.

coder --token <token> --url https://coder.deployment.com template ...

You can also use env vars:

CODER_SESSION_TOKEN=<token> coder --url https://coder.deployment.com template ...

Or write straight to the session file in ~/.config/coderv2/session and ~/.config/coderv2/url

@bpmct bpmct changed the title Continuous deployment support? Create long-lived tokens for CI/CD/automation (or tokens for a specific duration) Aug 25, 2022
@bpmct bpmct added this to the EE milestone Aug 25, 2022
@bpmct
Copy link
Member

bpmct commented Aug 25, 2022

Thanks for submitting the issue! I edited the description a bit so we can use this to track creating tokens and some docs around using Coder in CI.

@jaulz
Copy link
Author

jaulz commented Aug 25, 2022

Thanks for the quick response! I didn't realize that the token in the browser is actually the access token 😉 Great product by the way 😊

@bpmct
Copy link
Member

bpmct commented Sep 9, 2022

@ghuntley brought up an interesting point that we should consider before we add long-lived tokens. We may want to consider generating tokens in a searchable format so they can be picked up in security scans: https://docs.github.com/en/code-security/secret-scanning/about-secret-scanning

@ghuntley
Copy link
Contributor

ghuntley commented Sep 9, 2022

@ghuntley brought up an interesting point that we should consider before we add long-lived tokens. We may want to consider generating tokens in a searchable format so they can be picked up in security scans: https://docs.github.com/en/code-security/secret-scanning/about-secret-scanning

Also adding the convention into projects such as:

@bpmct
Copy link
Member

bpmct commented Sep 16, 2022

  • Token management/revocation will be an OSS feature
  • Down the road, we may add enterprise functions such as configurable token durations and custom scopes

@dcarrion87
Copy link
Contributor

We also have this requirement for pushing templates via Github actions. We're actually looking at something that can just keep templates in sync as they're updated. E.g. point coder at a repo revision of templates and it just takes care of it.

@f0ssel f0ssel self-assigned this Oct 5, 2022
@f0ssel f0ssel mentioned this issue Oct 5, 2022
@jaulz
Copy link
Author

jaulz commented Oct 7, 2022

@f0ssel thanks for the implementation! Is there any possibility to generate the token from the UI?

@ghuntley
Copy link
Contributor

Opening up #5409

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 a pull request may close this issue.

6 participants