-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Add support for requiring reason for access requests #49124
Add support for requiring reason for access requests #49124
Conversation
880bc0e
to
1e9fe39
Compare
// | ||
// If loginHint is provided, it will attempt to prune the list to a single role. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied this godoc from pruneResourceRequestRoles
which applicableSearchAsRoles
is calling to surface it a bit.
1e9fe39
to
c5b9345
Compare
{ | ||
name: "resource request: but require reason when another role allowing _role_ access requires reason for the role", | ||
currentRoles: []string{"fork-node-requester", "fork-access-requester-with-reason"}, | ||
requestResourceIDs: []types.ResourceID{ | ||
{ClusterName: clusterName, Kind: types.KindNode, Name: "fork-node"}, | ||
}, | ||
expectError: trace.BadParameter(`request reason must be specified (required for role "fork-access")`), | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the situation discussed here https://gravitational.slack.com/archives/C07QJQNGY2J/p1731620401319179
c5b9345
to
adeaa39
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First pass.
Could you take a look at UT failing on the AccessRequest test cases;
=== FAIL: lib/auth TestAccessRequestNonGreedyAnnotations/identity-resource-requester_requests_resource,_receives_identity_annotations (0.03s)
{"caller":"services/access_checker.go:1269","component":null,"level":"warning","message":"Failed to find roles in x509 identity for test-user. Fetching from backend. If the identity provider allows username changes, this can potentially allow an attacker to change the role of the existing user.","timestamp":"2024-11-18T19:32:40Z"}
{"timestamp":"2024-11-18T19:32:40Z","level":"debug","caller":"events/discard.go:147","message":"Discarding event","event_id":"","event_type":"role.created","event_time":"0001-01-01T00:00:00Z","event_index":0}
{"caller":"auth/auth.go:5216","component":"auth","level":"debug","message":"Creating Access Request 019340c3-4a76-7f2a-bf1e-70abfac19a85 with expiry 2024-11-18 20:32:39 +0000 UTC.","timestamp":"2024-11-18T19:32:40Z"}
auth_with_roles_test.go:8628:
Error Trace: /__w/teleport/teleport/lib/auth/auth_with_roles_test.go:8628
Error: Received unexpected error:
no roles configured in the "search_as_roles" for this user allow access to any requested resources. The user may already have access to all requested resources with their existing roles. resources: ["/localhost/node/server-identity"] roles: [identity-access] login: ""
Test: TestAccessRequestNonGreedyAnnotations/identity-resource-requester_requests_resource,_receives_identity_annotations
```
a2e458c
to
98728f7
Compare
@smallinsky @r0mant @fspmarshall I extracted and merged the dependencies, adapted to request.mode change and consider this ready to review now. |
98728f7
to
033826f
Compare
lib/services/access_request.go
Outdated
} | ||
|
||
if m.requireReasonForAllRoles { | ||
return trace.BadParameter("request reason must be specified (required request_access option in one of the roles)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would returning trace.AccessDenied here be more appropriate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's BadParameter. It's says reason is not given in the request, but it's required. I'd even say AccessDenied would be slightly confusing, as it may look as the user is not allowed to create Access Requests.
if len(allApplicableRoles) == 0 { | ||
allApplicableRoles = roles | ||
} else { | ||
allApplicableRoles = append(allApplicableRoles, roles...) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I think this can be simplified to just:
if len(allApplicableRoles) == 0 { | |
allApplicableRoles = roles | |
} else { | |
allApplicableRoles = append(allApplicableRoles, roles...) | |
} | |
allApplicableRoles = append(allApplicableRoles, roles...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I wanted to avoid allocation, but it doesn't matter much.
This got exposed while working on Access Request reason required PR: #49124
This changes the proto type (+validation) only to declutter the original PR #49124 The real changes are in - api/proto/teleport/legacy/types/types.proto - api/types/access_request.go - lib/auth/auth_with_roles.go - lib/auth/auth_with_roles_test.go The rest is all generated.
This changes the proto type (+validation) only to declutter the original PR #49124 The real changes are in - api/proto/teleport/legacy/types/types.proto - api/types/access_request.go - lib/auth/auth_with_roles.go - lib/auth/auth_with_roles_test.go The rest is all generated.
a5165aa
to
0148abe
Compare
This changes the proto type (+validation) only to declutter the original PR #49124 The real changes are in - api/proto/teleport/legacy/types/types.proto - api/types/access_request.go - lib/auth/auth_with_roles.go - lib/auth/auth_with_roles_test.go The rest is all generated.
f1e5833
to
8a56526
Compare
This got exposed while working on Access Request reason required PR: #49124
Issue #20164
TODO:
changelog: Added support for requiring reason for access requests (with a new
role.spec.allow.request.reason.mode
setting).