Skip to content

Extend declarative validation to MintJWT/MintCert requests - #1261

Open
shrutiyam-glitch wants to merge 9 commits into
agent-substrate:mainfrom
shrutiyam-glitch:mint-dv
Open

Extend declarative validation to MintJWT/MintCert requests#1261
shrutiyam-glitch wants to merge 9 commits into
agent-substrate:mainfrom
shrutiyam-glitch:mint-dv

Conversation

@shrutiyam-glitch

Copy link
Copy Markdown
Collaborator

Follow up on issue #1168 and the base PR #1215

Identity RPCs (MintJWT / MintCert)

  • Requests: Added full declarative validation tags (required, formatting, enum bounds) to all fields in MintJWTRequest and MintCertRequest.
  • Handlers: Validation now occurs immediately after authentication (the purpose != ATUNNEL policy check remains in the handler).

Notes

  • Stricter Validation: Empty atespace/actor_name can no longer mint malformed JWT subjects. UIDs must now be valid UUIDs.
  • Better Errors: MintJWT empty-audience error is now an InvalidArgument (was Unknown) checked before disk I/O. MintCert's atespace-on-global-ref error is now typed Forbidden (was Invalid).

Testing

  • Added 20 new table-driven test cases (TestValidateMintJWTRequest / TestValidateMintCertRequest), as these requests previously lacked validation tests.
  • Updated existing verb tests to match the new generated error shapes.
  • All test suites (controlapi, functionaltest, etc.), go vet, and gofmt pass cleanly.
  • Tests pass
  • Appropriate changes to documentation are included in the PR

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, one question

"Stale": {requestUID: func(string) string { return "uid-of-a-previous-incarnation" }, wantCode: codes.FailedPrecondition},
// The stale uid is well-formed on purpose: a malformed one is rejected
// as INVALID_ARGUMENT by request validation before the guard runs.
"Stale": {requestUID: func(string) string { return "9d1f7b06-3c58-4a2e-8b40-5f7c1e9a2d63" }, wantCode: codes.FailedPrecondition},

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

what is this string?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this uid should come from somewhere?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is a random UID that is assumed not to collide with the UID randomly picked by the store when it created the actor. I don't think we need the agent comment.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done.

@ahmedtd

Copy link
Copy Markdown
Collaborator

FYI I am working on a PR to move MintJWT / MintCert into the main API, and remove the dedicated ActorIdentity API. It seems clear from the authorization discussion that we will be able to handle any needed authorization using the overall authz framework we choose.

"Stale": {requestUID: func(string) string { return "uid-of-a-previous-incarnation" }, wantCode: codes.FailedPrecondition},
// The stale uid is well-formed on purpose: a malformed one is rejected
// as INVALID_ARGUMENT by request validation before the guard runs.
"Stale": {requestUID: func(string) string { return "9d1f7b06-3c58-4a2e-8b40-5f7c1e9a2d63" }, wantCode: codes.FailedPrecondition},

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is a random UID that is assumed not to collide with the UID randomly picked by the store when it created the actor. I don't think we need the agent comment.


// +k8s:required
// +k8s:minimum=1
// +k8s:maximum=1 # keep this in sync with the ActorCertificatePurpose enum

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I am not sure we need to try to guard the enum values using k8s validation logic. Our implementation has to throw an error on an unrecognized purpose, and the error message will be better from there.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah
Actually, there is +k8s:enum in DV - https://kubernetes.io/docs/reference/using-api/declarative-validation/#tag-enum (stability level:beta though)
But, this was the kind of practice everywhere - https://github.com/agent-substrate/substrate/blob/main/pkg/proto/ateapipb/ateapi.proto#L443-L449, hence followed it for uniformity.

cc: Tim Hockin (@thockin)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

sorry, nvm.
looks like +k8s:enum only works on string types. The proto enums compile to int32, so the tag can't be used on ours.

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.

3 participants