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

Fix Admin MFA required check #51618

Merged
merged 3 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion api/mfa/ceremony.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ func PerformAdminActionMFACeremony(ctx context.Context, mfaCeremony CeremonyFn,
},
}

resp, err := mfaCeremony(ctx, challengeRequest, WithPromptReasonAdminAction())
// Remove MFA resp from context if set. This way, the mfa required
// check will return true as long as MFA for admin actions is enabled,
// even if the current context has a reusable MFA. v18 server will
// return this requirement as expected.
// TODO(Joerger): DELETE IN v19.0.0
ceremonyCtx := ContextWithMFAResponse(ctx, nil)

resp, err := mfaCeremony(ceremonyCtx, challengeRequest, WithPromptReasonAdminAction())
return resp, trace.Wrap(err)
}
10 changes: 5 additions & 5 deletions lib/auth/auth_with_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -5984,15 +5984,15 @@ func (a *ServerWithRoles) IsMFARequired(ctx context.Context, req *proto.IsMFAReq
// Check if MFA is required for admin actions. We don't currently have
// a reason to check the name of the admin action in question.
if _, ok := req.Target.(*proto.IsMFARequiredRequest_AdminAction); ok {
if a.context.AdminActionAuthState == authz.AdminActionAuthUnauthorized {
if a.context.AdminActionAuthState == authz.AdminActionAuthNotRequired {
return &proto.IsMFARequiredResponse{
Required: true,
MFARequired: proto.MFARequired_MFA_REQUIRED_YES,
Required: false,
MFARequired: proto.MFARequired_MFA_REQUIRED_NO,
}, nil
} else {
return &proto.IsMFARequiredResponse{
Required: false,
MFARequired: proto.MFARequired_MFA_REQUIRED_NO,
Required: true,
MFARequired: proto.MFARequired_MFA_REQUIRED_YES,
}, nil
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/auth/auth_with_roles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9545,15 +9545,15 @@ func TestIsMFARequired_AdminAction(t *testing.T) {
name: "mfa verified",
adminActionAuthState: authz.AdminActionAuthMFAVerified,
expectResp: &proto.IsMFARequiredResponse{
Required: false,
MFARequired: proto.MFARequired_MFA_REQUIRED_NO,
Required: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think it's worth testing these using CreateAuthenticationChallenge instead? I've read the PR description a few times now but I confess I'm still a bit confused by it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CreateAuthenticateChallenge calls authWithRoles.IsMFARequired directly, so I think it's ok. I reorganized the PR description, hopefully the relation makes more sense now.

MFARequired: proto.MFARequired_MFA_REQUIRED_YES,
},
}, {
name: "mfa verified with reuse",
adminActionAuthState: authz.AdminActionAuthMFAVerifiedWithReuse,
expectResp: &proto.IsMFARequiredResponse{
Required: false,
MFARequired: proto.MFARequired_MFA_REQUIRED_NO,
Required: true,
MFARequired: proto.MFARequired_MFA_REQUIRED_YES,
},
},
} {
Expand Down
Loading