Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(vault-jwt): allow specifying the vault jwt token directly #436

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 21 commits into from
May 8, 2025

Conversation

moo-im-a-cow
Copy link
Contributor

this PR allows you to pass the desired jwt token to the vault-jwt module as a variable, for cases when you want to use a different jwt token to the one used to authenticate to vault

if not specified, it defaults to data.coder_workspace_owner.me.oidc_access_token.

@cdr-bot cdr-bot bot added the community Pull Requests and issues created by the community. label Apr 22, 2025
Copy link
Member

@matifali matifali left a comment

Choose a reason for hiding this comment

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

Not a vault expert at all. But as far as I understand the the workspace scoped secrets need to be pre created in vault. How would one do that.
In other words, I agree with use case to provide workspace only secrets access but is concerned if it makes the config difficult on the vault side. How would one provision these secrets? For what type of secrets this is most useful for.

Thanks.

@moo-im-a-cow
Copy link
Contributor Author

moo-im-a-cow commented Apr 22, 2025

Not a vault expert at all. But as far as I understand the the workspace scoped secrets need to be pre created in vault. How would one do that.

one option is for someone with permission to create at the correct path would have to create them with the relevant command, an admin user with their "access everything" policy

e.g. for kv, it would be something like vault kv put -mount=kv apps/coder/username/workspace/supersecret password=password
image

but more likely, the workspace user would generate a secret inside the workspace, and save it to vault (by running the above command in the workspace), and then it can never be retrieved from outside

policy could be created for allowing anyone access as long as they are accessing using a specific coder template

additionally, one of the scenarios im considering is an admin user who only has admin access from inside coder. policies granting full access to whatever, but only when authenticated with a specific mount/role, theres no specific secret, more just any and all secrets
(similar to how the only user with permission to create and manage auth methods and engines in my vault instance is a token generated by gitlab for a CI job in a specific repository, using exactly the same sort of configuration here)

something similar i already have set up, is that a specific k8s service account in the coder namespace is the only user capable of accessing the oidc client secret for coder, which is stored in vault
the disk pvc service account in k8s is the only user that can create or view disk encryption keys for the cluster, also in vault

another example of how this could be useful is allow you to use vault to generate k8s keys or aws access keys, but you can only do it from a trustworthy environment, you must be using template X

config difficult on the vault side
it can be as easy or difficult as the person managing it is willing to make it, assign an existing policy to the role, doesnt even need any configuration other than what they already have, or they can use every variable available
just because the variables are included in the token doesnt mean you have to use them in vault,
but if they're there, you have the option to use them if you want

additionally, this is just one of many many ways to set it up, you could have it generate with none of the fields and just authenticate the user, link the token to the user's entity in vault, 1:1 same permissions the user has outside, same secrets
or you can do more complex like what i'm using it for

but the ability to make complex policies based on data from the authentication source is exactly what you want with vault.

the difficulty is sorta similar to coder templates, if you wanted to you could make it so complicated and difficult to use, or you could make it easy, that's entirely up to the person who generates the token to pass to the module, and the person who writes the policies to decide what to do

I would appreciate it if we could also add a vault policy that can use this new jwt token

done, I added an example vault policy, as well as an example command for configuring the mount role

@matifali
Copy link
Member

Hi @moo-im-a-cow can you run bun fmt?

@moo-im-a-cow
Copy link
Contributor Author

@matifali is there a way to override an error in the "ci/pretty" job?

vault-jwt hcl code block should be tf

the hcl code block it refers to is is an example vault policy, not terraform, so hcl is the correct code block type

@matifali
Copy link
Member

Thanks. I think we need to handle this in our validation script.
We use a prettier plugin to format code blocks within markdown that only used to work with tf blocks that's why the condition. I will check if we can also allow hcl blocks.

@matifali matifali requested a review from mafredri May 5, 2025 08:04
@matifali
Copy link
Member

matifali commented May 5, 2025

@mafredri, what is the best way to pass this prettier validation check? AFAIR, we did this as the plugin we are using is not able to format hcl blocks, and only works for tf blocks.

@DevelopmentCats
Copy link
Contributor

I have changed the syntax and code block in the readme for the Vault Policy example.

I will do one last test of this module using these new blocks to make sure it works properly before Accepting

@DevelopmentCats
Copy link
Contributor

I'm going to pull this locally to test it before approving this but everything is looking good now.

Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

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

Just a couple minor nits, otherwise LGTM 👍🏻

sub = "${data.coder_workspace.me.id}"
aud = "https://vault.example.com"
iat = provider::time::rfc3339_parse(plantimestamp()).unix
# exp = timeadd(timestamp(), 3600)
Copy link
Member

Choose a reason for hiding this comment

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

This should either be removed or have an associated comment (uncomment to ...).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you mean just the exp field? or the sub, aud, iat, exp fields?
(github shows you replying to 4 lines so just making sure i have the correct context)
I also realised the exp line is invalid, i'll have to update it anyway so that it gives a unix timestamp instead of text timestamp

Copy link
Contributor Author

Choose a reason for hiding this comment

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

assuming you only meant the exp field, i've fixed it up and added a comment describing it and the pro/con of uncommenting it (making the token expire)

Copy link
Member

@matifali matifali left a comment

Choose a reason for hiding this comment

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

Please bump the version.

moo-im-a-cow and others added 6 commits May 8, 2025 19:36
Co-authored-by: Mathias Fredriksson <[email protected]>
Co-authored-by: Mathias Fredriksson <[email protected]>
Co-authored-by: Mathias Fredriksson <[email protected]>
@matifali matifali merged commit 43ed02f into coder:main May 8, 2025
4 checks passed
@matifali
Copy link
Member

matifali commented May 8, 2025

Should be available in version 1.1.0
Thanks a lot for the contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Pull Requests and issues created by the community.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants