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

WI: interpolate parent job ID in vault.default_identity.extra_claims #23817

Merged
merged 2 commits into from
Sep 3, 2024

Conversation

tgross
Copy link
Member

@tgross tgross commented Aug 14, 2024

When we interpolate job fields for the vault.default_identity.extra_claims block, we forgot to use the parent job ID when that's available (as we do for all other claims). This changeset fixes the bug and adds a helper method that'll hopefully remind us to do this going forward.

Also added a missing changelog entry for #23675 where we implemented the extra_claims block originally, which shipped in Nomad 1.8.3.

Fixes: #23798
Ref: https://hashicorp.atlassian.net/browse/NET-10714

@tgross tgross force-pushed the b-interpolate-claims-job-parent-id branch from f4d730e to fc05cbe Compare August 14, 2024 19:17
@tgross tgross added theme/vault type/bug theme/batch Issues related to batch jobs and scheduling labels Aug 14, 2024
@tgross tgross added this to the 1.8.4 milestone Aug 14, 2024
@tgross tgross force-pushed the b-interpolate-claims-job-parent-id branch from fc05cbe to 378d4b3 Compare August 14, 2024 19:21
@tgross tgross changed the title WI: interpolate parent job ID in vault.default_identity.extra_claims WI: interpolate parent job ID in vault.default_identity.extra_claims Aug 14, 2024
@tgross tgross marked this pull request as ready for review August 14, 2024 19:22
@tgross tgross requested a review from schmichael August 14, 2024 19:22
@tgross tgross requested a review from gulducat August 14, 2024 19:22
Copy link
Member

@gulducat gulducat left a comment

Choose a reason for hiding this comment

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

lgtm!

nomad/structs/workload_id_test.go Show resolved Hide resolved
@@ -200,7 +201,7 @@ func TestNewIdentityClaims(t *testing.T) {
},
"job/group/task/alt-identity": {
Namespace: "default",
JobID: "job",
JobID: "parentJob",
TaskName: "task",
Claims: jwt.Claims{
Subject: "global:default:job:group:task:alt-identity",
Copy link
Member Author

@tgross tgross Aug 14, 2024

Choose a reason for hiding this comment

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

@schmichael I've just now noticed we don't use the parent ID for the Subject claim... is that intentional or did we repeat the same bug there?

Copy link
Member

Choose a reason for hiding this comment

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

We repeated the same bug. I'm sure I just forgot about the distinction between Parent/Child IDs when writing it initially. :(

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll fix that in a separate PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

@tgross tgross added the backport/1.8.x backport to 1.8.x release line label Aug 14, 2024
Copy link
Contributor

@EtienneBruines EtienneBruines left a comment

Choose a reason for hiding this comment

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

Even though I cannot come up with an actual use-case, there might be instances where someone wants to use the /periodic-123456 suffix as part of their claim. Or something else somewhat unique to the individual run (e.g. allocation ID).

Use-cases will probably be related to the fact that the field you select in Vault for the user_claim needs to be unique for the combination of claims. For example:

Before Nomad v1.8.3 you had to configure /sub as user_claim if you wanted different dynamic database credentials (Vault database secret engine) per-task within the same Nomad job. For example one migrations-tasks with full admin rights to the databse and one webserver-task with limited permissions. If you configured something else as the user_claim, e.g. nomad_job_id, then the tasks would 'overwrite' each other, pointing to the wrong JWT claims. I could imagine something similar happening to someone when it comes to unique invocations of periodic/batch jobs, providing a need for something unique-ish - be that alloc.id or the /periodic-123456 suffix.

Whether that's just an additional interpolate variable or whether it's part of the Subject claim isn't up to me, but providing something somewhere that is unique to the allocation/run might be beneficial. As of right now, it'd only be available as one of the builtin claims and not part of anything you can interpolate into extra claims.

When we interpolate job fields for the `vault.default_identity.extra_claims`
block, we forgot to use the parent job ID when that's available (as we do for
all other claims). This changeset fixes the bug and adds a helper method that'll
hopefully remind us to do this going forward.

Also added a missing changelog entry for #23675 where we implemented the
`extra_claims` block originally, which shipped in Nomad 1.8.3.

Fixes: #23798
@tgross
Copy link
Member Author

tgross commented Sep 3, 2024

providing a need for something unique-ish - be that alloc.id

nomad_alloc_id is already one of the claims. In fact, that's how Nomad adds extra validation to requests made to the Nomad API -- workload identities for terminal allocations are invalid. But we should make that available for interpolation here as well.

tgross added a commit that referenced this pull request Sep 3, 2024
When we use the job ID in creating the subject claim (`sub`) for workload
identities, we forgot to use the parent job ID when that's available. Child job
IDs have a random component that makes them unsuitable for the subject field.

Ref: #23817 (comment)
Ref: https://hashicorp.atlassian.net/browse/NET-10714
tgross added a commit that referenced this pull request Sep 3, 2024
When we use the job ID in creating the subject claim (`sub`) for workload
identities, we forgot to use the parent job ID when that's available. Child job
IDs have a random component that makes them unsuitable for the subject field.

Ref: #23817 (comment)
Ref: https://hashicorp.atlassian.net/browse/NET-10714
Copy link

github-actions bot commented Jan 2, 2025

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 2, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport/1.8.x backport to 1.8.x release line theme/batch Issues related to batch jobs and scheduling theme/vault theme/workload-identity type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

extra_claims job ID without periodic suffix for batch jobs
4 participants