Skip to content

Refactor so we validate before auth on the vault#22835

Open
russell-stern wants to merge 3 commits into
developfrom
refactor/validate_before_auth
Open

Refactor so we validate before auth on the vault#22835
russell-stern wants to merge 3 commits into
developfrom
refactor/validate_before_auth

Conversation

@russell-stern

Copy link
Copy Markdown
Contributor

No description provided.

@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

✅ No conflicts with other open PRs targeting develop

@github-actions

Copy link
Copy Markdown
Contributor

I see you updated files related to core. Please run make gocs in the root directory to add a changeset as well as in the text include at least one of the following tags:

  • #added For any new functionality added.
  • #breaking_change For any functionality that requires manual action for the node to boot.
  • #bugfix For bug fixes.
  • #changed For any change to the existing functionality.
  • #db_update For any feature that introduces updates to database schema.
  • #deprecation_notice For any upcoming deprecation functionality.
  • #internal For changesets that need to be excluded from the final changelog.
  • #nops For any feature that is NOP facing and needs to be in the official Release Notes for the release.
  • #removed For any functionality/config that is removed.
  • #updated For any functionality that is updated.
  • #wip For any change that is not ready yet and external communication about it should be held off till it is feature complete.

@trunk-io

trunk-io Bot commented Jun 12, 2026

Copy link
Copy Markdown

Static BadgeStatic BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

@russell-stern russell-stern force-pushed the refactor/validate_before_auth branch from d48922d to d937b6d Compare June 12, 2026 17:44
@cl-sonarqube-production

Copy link
Copy Markdown

@russell-stern russell-stern marked this pull request as ready for review June 12, 2026 17:59
@russell-stern russell-stern requested review from a team as code owners June 12, 2026 17:59

@prashantkumar1982 prashantkumar1982 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

General comment.
I think that both before and after the refactor, we have a lot of code around validation fragmented in different places.
Very hard to reason or understand which component is responsible for what, where does the namespace get inserted if empty, where do we validate inner owner matches authorized one, etc.
Perhaps in this, or later PR, we should consolidate and make the code simpler?

Also @cedric-cordenier

PS: My upcoming PR for owner canonicalization also struggles with these challenges. We ideally should mutate the request only at 1 place inside capability. And remove mutations from all other places.

var Methods = append(append([]string(nil), UserSecretsMethods...), MethodPublicKeyGet)

// IsUserSecretsMethod reports whether method is a user-facing secrets management JSON-RPC method.
func IsUserSecretsMethod(method string) bool {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: rename to IsUserFacingMethod?

// Every vault JSON-RPC method must have an explicit case here (binding logic or an intentional skip).
// Callers must validate request shape before authorization so malformed params surface as
// InvalidParamsError instead of authorization failures.
func bindVaultOwners(req jsonrpc.Request[json.RawMessage], workflowOwner string) error {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: rename to validateBoundVaultOwners

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

just trying to add a hint in the method name that it is read-only for requests.

if err := stripPrefixedRequestIDFromParams(&authReq, originalRequestID); err != nil {
h.lggr.Errorw("failed to normalize gateway request for authorization", "method", req.Method, "requestID", originalRequestID, "error", err)
if err := h.requestValidator.PrepareUserJSONRPCRequest(ctx, req, UserJSONRPCValidationOptions{
SkipLabelValidation: true,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

SkipLabelValidation should be false on here, since it is inside the Vault Node, where masterpublickey is always available

// Prefix request id with authorizedOwner, to ensure uniqueness across different owners
// We do this ourselves to ensure the ID is unique and can't be tampered with by the user.
req.ID = authorizedOwner + vaulttypes.RequestIDSeparator + req.ID
if err := h.FinalizeAuthorizedJSONRPCRequest(&req, req.ID); err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This will mutate the request by adding an empty namespace if it wasn't there right?
I see this mutation was also existing in old code.
I'm a bit lost, how were we mutating the request earlier, without breaking the requestDigest on the gw_handler side.

Doesn't it mean the mutation would change the request digest, and thus the vault node would never match the allowlist digest?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This file should likely be inside this package: core/capabilities/vault/vaultutils

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.

2 participants