Skip to content
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

Allow annotating service accounts with arbitrary tags for policy templating #132

Closed
wants to merge 8 commits into from

Conversation

dovys
Copy link

@dovys dovys commented Feb 2, 2022

Addresses hashicorp#85

We took Mark's proposed design and added support for defining annotations on service accounts that can later on be used in policy templating.

apiVersion: v1
kind: ServiceAccount
metadata:
  name: example-account
  namespace: default
  annotations:
    auth-metadata.vault.hashicorp.com/service-role: example-value

Which you can then use in policies as so

{{identity.entity.aliases.${vault_auth_backend.kubernetes.accessor}.metadata.service_role}}

Who the change affects or is for (stakeholders)?
The change is behind a config flag called enable_custom_metadata_from_annotations so it should not affect any of the existing integrations.
In order to enable the flag users will have to update the clusterrole and allow Vault to read service accounts. If this change is accepted we'll open PRs to update various docs, terraform providers, etc.
This will also introduce another roundtrip to the Kubernetes API, however we are using a pooled tcp client so hopefully not too many new open connections.

Why is the change needed?
At @monzo we want to use fully qualified service names for certificates issued under Vault's PKI, ie service.profile. At the same time we want policies and roles to be very strict so service.profile is not allowed to obtain certificates for service.id. As we have over 2000 microservices and they grow at a steady rate it's not feasible to write a new policy for each. Allowing us to annotate service accounts with the fully qualified service name and then use it in PKI mount allowed_domains with templating solves this issue.

Design of Change

We've largely adhered to the current code style present in the repo.
All changes are behind a config flag enable_custom_metadata_from_annotations. Existing integrations are not affected until the flag is turned on.

Related Issues/Pull Requests

TBD - we'll create PRs for the terraform provider and docs when this PR has been largely agreed upon

Contributor Checklist

  • TBD Add relevant docs to upstream Vault repository, or sufficient reasoning why docs won’t be added yet
    My Docs PR Link
    Example
  • Add output for any tests not ran in CI to the PR description (eg, acceptance tests)
  • Backwards compatible

Dovydas Bartkevicius and others added 4 commits February 1, 2022 12:11
Addresses hashicorp#85

We took Mark's proposed design and added support for defining annotations on service accounts that can later on be used in policy templating.

```yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: example-account
  namespace: default
  annotations:
    vault.hashicorp.com/auth-metadata/service-role: example-value
```

Should allow us to use in policies as so
```
{{identity.entity.aliases.${vault_auth_backend.kubernetes.accessor}.metadata.service_role}}
```

The change is behind a config flag called `enable_custom_metadata_from_annotations` so it should not affect any of the existing integrations.
In order to enable the flag users will have to update the clusterrole and allow Vault to read service accounts. If this change is accepted we'll open PRs to update various docs, terraform providers, etc.
This will al so introduce another roundtrip to the Kubernetes API, however we are using a pooled tcp client so hopefully not too many new open connections.
Co-authored-by: Chongyang Shi <[email protected]>
Add support for using serviceaccount annotations
@hashicorp-cla
Copy link

hashicorp-cla commented Feb 2, 2022

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes


2 out of 4 committers have signed the CLA.

  • dovys
  • chongyangshi
  • nickrmc83
  • Dovydas Bartkevicius

Dovydas Bartkevicius seems not to be a GitHub user.
You need a GitHub account to be able to sign the CLA. If you already have a GitHub account, please add the email address used for this commit to your account.

Have you signed the CLA already but the status is still pending? Recheck it.

Chongyang and others added 2 commits February 8, 2022 16:51
@tomhjp
Copy link
Contributor

tomhjp commented Feb 9, 2022

Hi @dovys, thanks for raising this! I'm going to gather some feedback internally on the feature, and I'll get back to you as soon as I can.

@CodyKurtz
Copy link

Is there an update on this?

@CodyKurtz
Copy link

Hi @dovys, thanks for raising this! I'm going to gather some feedback internally on the feature, and I'll get back to you as soon as I can.

Any updates on this? Thank you

nickrmc83 and others added 2 commits November 24, 2022 17:36
With K8S 1.21 bound tokens are now the default which have the name and namespaces in a different location.
The wrapper functions take care of picking out the correct function automatically.
Use `namespace()` and `name()` wrapper functions
@thyton
Copy link
Contributor

thyton commented Jan 12, 2024

Thank you for your contribution, @dovys! We started a fresh PR #226 taking inspiration from this one. We're going to close your PR.

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.

7 participants