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

Add support for requiring reason for access requests #49124

Merged

Conversation

kopiczko
Copy link
Contributor

@kopiczko kopiczko commented Nov 18, 2024

Issue #20164

TODO:

changelog: Added support for requiring reason for access requests (with a new role.spec.allow.request.reason.mode setting).

@kopiczko kopiczko force-pushed the kopiczko/add-role.spec.allow.request.reason.required branch 6 times, most recently from 880bc0e to 1e9fe39 Compare November 18, 2024 19:01
Comment on lines +312 to +325
//
// If loginHint is provided, it will attempt to prune the list to a single role.
Copy link
Contributor Author

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.

@kopiczko kopiczko marked this pull request as ready for review November 18, 2024 19:02
@kopiczko kopiczko force-pushed the kopiczko/add-role.spec.allow.request.reason.required branch from 1e9fe39 to c5b9345 Compare November 18, 2024 19:03
Comment on lines +2293 to +2344
{
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")`),
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kopiczko kopiczko force-pushed the kopiczko/add-role.spec.allow.request.reason.required branch from c5b9345 to adeaa39 Compare November 18, 2024 19:07
@r0mant r0mant requested review from fspmarshall and removed request for ryanclark and flyinghermit November 18, 2024 20:51
Copy link
Contributor

@smallinsky smallinsky left a 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
      ```

lib/services/access_request.go Outdated Show resolved Hide resolved
lib/services/access_request.go Outdated Show resolved Hide resolved
lib/services/access_request.go Outdated Show resolved Hide resolved
lib/services/access_request.go Show resolved Hide resolved
@kopiczko kopiczko force-pushed the kopiczko/add-role.spec.allow.request.reason.required branch from a2e458c to 98728f7 Compare November 22, 2024 20:30
@kopiczko kopiczko marked this pull request as ready for review November 22, 2024 20:48
@github-actions github-actions bot added the rfd Request for Discussion label Nov 22, 2024
@kopiczko
Copy link
Contributor Author

@smallinsky @r0mant @fspmarshall I extracted and merged the dependencies, adapted to request.mode change and consider this ready to review now.

@kopiczko kopiczko force-pushed the kopiczko/add-role.spec.allow.request.reason.required branch from 98728f7 to 033826f Compare November 25, 2024 10:38
@smallinsky smallinsky self-requested a review November 25, 2024 10:54
lib/services/access_request.go Outdated Show resolved Hide resolved
lib/services/access_request.go Outdated Show resolved Hide resolved
}

if m.requireReasonForAllRoles {
return trace.BadParameter("request reason must be specified (required request_access option in one of the roles)")
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

lib/services/access_request.go Outdated Show resolved Hide resolved
lib/services/access_request.go Show resolved Hide resolved
Comment on lines +1366 to +1377
if len(allApplicableRoles) == 0 {
allApplicableRoles = roles
} else {
allApplicableRoles = append(allApplicableRoles, roles...)
}
Copy link
Collaborator

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:

Suggested change
if len(allApplicableRoles) == 0 {
allApplicableRoles = roles
} else {
allApplicableRoles = append(allApplicableRoles, roles...)
}
allApplicableRoles = append(allApplicableRoles, roles...)

Copy link
Contributor Author

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.

lib/services/access_request.go Outdated Show resolved Hide resolved
github-actions bot pushed a commit that referenced this pull request Nov 26, 2024
This got exposed while working on Access Request reason required PR:
#49124
kopiczko added a commit that referenced this pull request Nov 27, 2024
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.
kopiczko added a commit that referenced this pull request Nov 27, 2024
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.
@kopiczko kopiczko added backport/branch/v17 and removed rfd Request for Discussion labels Nov 27, 2024
@kopiczko kopiczko force-pushed the kopiczko/add-role.spec.allow.request.reason.required branch from a5165aa to 0148abe Compare November 27, 2024 10:37
github-merge-queue bot pushed a commit that referenced this pull request Nov 27, 2024
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.
@kopiczko kopiczko force-pushed the kopiczko/add-role.spec.allow.request.reason.required branch from f1e5833 to 8a56526 Compare November 27, 2024 16:06
@kopiczko kopiczko enabled auto-merge November 27, 2024 16:08
@kopiczko kopiczko added this pull request to the merge queue Nov 27, 2024
Merged via the queue into master with commit 6c0d997 Nov 27, 2024
45 of 46 checks passed
@kopiczko kopiczko deleted the kopiczko/add-role.spec.allow.request.reason.required branch November 27, 2024 16:44
@public-teleport-github-review-bot

@kopiczko See the table below for backport results.

Branch Result
branch/v17 Failed

github-merge-queue bot pushed a commit that referenced this pull request Nov 27, 2024
This got exposed while working on Access Request reason required PR:
#49124
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants