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

approle: Make invalid role_id a 400 error instead of 500 #4470

Merged
merged 7 commits into from
May 4, 2018

Conversation

vishalnayak
Copy link
Contributor

Fixes #4451

@vishalnayak vishalnayak added this to the 0.10.2 milestone Apr 27, 2018
// Checks if the Role represented by the RoleID still exists
func (b *backend) validateRoleID(ctx context.Context, s logical.Storage, roleID string) (*roleStorageEntry, string, error) {
// Validates the supplied RoleID and SecretID
func (b *backend) validateCredentials(ctx context.Context, req *logical.Request, data *framework.FieldData) (*roleStorageEntry, string, map[string]string, string, error, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider naming the return parameters. The list is long, many are strings, and much of the usage is nil, "",... which makes it hard to infer what they even are.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Removed.

@@ -152,7 +138,7 @@ func (b *backend) validateCredentials(ctx context.Context, req *logical.Request,
}
}

return role, roleName, metadata, secretID, nil, nil
return role, roleIDIndex.Name, metadata, secretID, nil, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we return secretID? The only caller doesn't even use 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.

I removed the function as it had a single caller.


roleLock := b.roleLock(roleName)
roleLock.RLock()
defer roleLock.RUnlock()
Copy link
Member

Choose a reason for hiding this comment

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

Do you actually need the lock after the roleEntry call? If not, can you just manually unlock instead of deferring until the end? That way you're not holding on to the role lock while also contending for the read/write locks for the secret ID.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't need the lock on the role for long. Releasing it sooner now as per feedback.

secretIDLock := b.secretIDLock(secretIDHMAC)
secretIDLock.RLock()
secretIDUnlockFunc := secretIDLock.RUnlock
defer func() {
Copy link
Member

Choose a reason for hiding this comment

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

Honestly, I'd prefer if you didn't do this. In the two return scenarios below you could just unlock manually. Then when you're in the switch, in the first case you know it'll stay a read lock and you can immediately defer the RUnlock; in the second case you know you'll need to switch it so you can runlock, lock, immediately defer the write lock.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@vishalnayak vishalnayak merged commit 977171d into master May 4, 2018
@vishalnayak vishalnayak deleted the approle-error-handling branch May 4, 2018 14:15
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