Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add feature-gated audit id handler that validates audit ids #129995

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
Loading
from

Conversation

everettraven
Copy link

What type of PR is this?

/kind bug

What this PR does / why we need it:

Outlined in #127801, there is no validation performed on audit ids leading to potential security risks as injecting a malicious string may result in vulnerabilities for systems that do some processing on audit ids.

This PR addresses this issue by:

  • Adding a new feature gate, AuditIDValidation, that is enabled by default
  • Updates the filters.withAuditInit() function with logic to validate audit ids, adding 2 new input parameters to the function signature:
    • A function for validating an audit id
    • A http.Handler to call ServeHTTP() on if the audit id is invalid
  • Adds a new filters.WithValidatingAuditInit() function that calls filters.withAuditInit() providing inputs for the new parameters added to filters.withAuditInit()
  • Updates the apiserver default handler chain to use filters.WithValidatingAuditInit() when the AuditIDValidation feature gate is enabled and filters.WithAuditInit() when it is disabled.

Which issue(s) this PR fixes:

Fixes #127801

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Added validation to audit ids specified in the 'Audit-ID' request header. Audit IDs must be less than 64 characters in length and only contain alphanumeric characters separated by hyphens ('-'). Audit ID validation can be disabled by disabling the `AuditIDValidation` feature gate.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. kind/bug Categorizes issue or PR as related to a bug. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Feb 5, 2025
@k8s-ci-robot
Copy link
Contributor

Welcome @everettraven!

It looks like this is your first PR to kubernetes/kubernetes 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kubernetes has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Feb 5, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @everettraven. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label Feb 5, 2025
@k8s-ci-robot k8s-ci-robot added area/apiserver sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Feb 5, 2025
@everettraven
Copy link
Author

/sig auth

@k8s-ci-robot k8s-ci-robot added the sig/auth Categorizes an issue or PR as relevant to SIG Auth. label Feb 5, 2025
@everettraven
Copy link
Author

/remove sig/api-machinery

@everettraven
Copy link
Author

/remove-label sig/api-machinery

@k8s-ci-robot
Copy link
Contributor

@everettraven: The label(s) /remove-label sig/api-machinery cannot be applied. These labels are supported: api-review, tide/merge-method-merge, tide/merge-method-rebase, tide/merge-method-squash, team/katacoda, refactor, ci-short, ci-extended, ci-full, official-cve-feed. Is this label configured under labels -> additional_labels or labels -> restricted_labels in plugin.yaml?

In response to this:

/remove-label sig/api-machinery

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

BtreeWatchCache: {
{Version: version.MustParse("1.32"), Default: true, PreRelease: featuregate.Beta},
AuditIDValidation: {
{Version: version.MustParse("1.33"), Default: true, PreRelease: featuregate.GA},
Copy link
Author

Choose a reason for hiding this comment

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

Marked this as a GA feature gate due to #127801 (comment) - if there is a more appropriate value to place here, please let me know!

@@ -60,6 +94,21 @@ func withAuditInit(handler http.Handler, newAuditIDFunc func() string) http.Hand
w.Header().Set(auditinternal.HeaderAuditID, auditID)
}

if auditIDValidationFunc != nil {
Copy link
Author

Choose a reason for hiding this comment

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

As it stands, if there is a validation function specified it will validate a generated audit ID as well. #127801 originally specifies that client provided audit ids should be validated. From what I could tell, when using WithValidatingAuditInit(), the validation function used (validateAuditID()) should always return valid for the defaultNewAuditID() function.

This means it should be safe to assume that the failure will only happen on client provided audit IDs, but in theory if the defaultNewAuditID() is updated to no longer always return a valid generated audit ID, some requests may fail due to this validation being run.

Open Question(s) to reviewers:

  • Should the audit id validation be skipped if an audit id is generated?
  • Are there any side effects to allowing generated audit ids to not adhere to the same validation requirements as client provided audit ids?
    • Example: User supplies audit id that was previously generated. They receive a 400 status code. Is this a bad thing?

@seans3
Copy link
Contributor

seans3 commented Feb 6, 2025

/ok-to-test
/remove-sig api-machinery

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. area/cloudprovider area/dependency Issues or PRs related to dependency changes sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. and removed sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 6, 2025
@k8s-ci-robot k8s-ci-robot added sig/cloud-provider Categorizes an issue or PR as relevant to SIG Cloud Provider. sig/node Categorizes an issue or PR as relevant to SIG Node. wg/device-management Categorizes an issue or PR as relevant to WG Device Management. labels Feb 11, 2025
@everettraven everettraven force-pushed the upstream/audit-id-validation branch from 3fff551 to 90f3033 Compare February 11, 2025 18:55
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 11, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: everettraven
Once this PR has been reviewed and has the lgtm label, please assign jpbetz for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Signed-off-by: Bryce Palmer <bpalmer@redhat.com>
@everettraven everettraven force-pushed the upstream/audit-id-validation branch from 90f3033 to 6f683c5 Compare February 11, 2025 19:04
Comment on lines +216 to +225
} else {
// if we are running a validating audit-id init test
// and the inner handler isn't expected to have run, we
// are testing an invalid audit-id scenario. In that case,
// ensure the status code returned is representative of
// a bad request (400).
if w.Code != http.StatusBadRequest {
t.Errorf("WithValidatingAuditID: expected status code %v but got %v", http.StatusBadRequest, w.Code)
}
}
Copy link
Author

Choose a reason for hiding this comment

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

Linter seems to be upset about this else statement here. I think this logic makes sense as is. Open to changing this to an else if if reviewers disagree that this is reasonable to override.

… handler that validates audit ids

Signed-off-by: Bryce Palmer <bpalmer@redhat.com>
…Validation feature gate is enabled

Signed-off-by: Bryce Palmer <bpalmer@redhat.com>
@everettraven everettraven force-pushed the upstream/audit-id-validation branch from 6f683c5 to 3d7d3c9 Compare February 11, 2025 21:16
@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Feb 11, 2025

@everettraven: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubernetes-linter-hints 3d7d3c9 link false /test pull-kubernetes-linter-hints

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@everettraven
Copy link
Author

/remove-sig node cloud-provider device-management

@k8s-ci-robot k8s-ci-robot removed sig/node Categorizes an issue or PR as relevant to SIG Node. sig/cloud-provider Categorizes an issue or PR as relevant to SIG Cloud Provider. labels Feb 13, 2025
@k8s-ci-robot
Copy link
Contributor

@everettraven: Those labels are not set on the issue: sig/device-management

In response to this:

/remove-sig node cloud-provider device-management

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@everettraven
Copy link
Author

/remove-wg device-management

@k8s-ci-robot k8s-ci-robot removed the wg/device-management Categorizes an issue or PR as relevant to WG Device Management. label Feb 13, 2025
@cici37
Copy link
Contributor

cici37 commented Feb 18, 2025

/remove-sig api-machinery

@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. labels Feb 18, 2025
@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@enj
Copy link
Member

enj commented Mar 10, 2025

/assign ritazh

@enj enj moved this from Needs Triage to In Review in SIG Auth Mar 10, 2025
@enj
Copy link
Member

enj commented Mar 10, 2025

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Mar 10, 2025
@dims dims added the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label May 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/apiserver area/cloudprovider area/dependency Issues or PRs related to dependency changes cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/auth Categorizes an issue or PR as relevant to SIG Auth. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Archived in project
Status: In Review
Status: not-only-sig-node
Development

Successfully merging this pull request may close these issues.

Input validation on client provided audit-id
7 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.