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 OpsWorks 'set permissions' failing to set ssh access. #1038

Merged

Conversation

charles-at-geospock
Copy link
Contributor

When the permissions being changed in OpsWorks were only the flags
for the sudo and ssh permissions of the current user, terraform
would send a 'level' parameter containing an empty string. This is
not valid, and AWS will respond to the request saying you cannot
change your own privilege level. Clearly an empty string ("") is
not taken as being 'unchanged', but nil is.

This change detects that an empty string would be sent to AWS and
if so, sends 'nil' in its place (which makes the parameter unset,
and allows the operation). Consequently, this allows the OpsWorks
SetPermissions operation to complete, changing the Sudo or SSH
permissions.

Fixes: #458

When the permissions being changed in OpsWorks were only the flags
for the sudo and ssh permissions of the current user, terraform
would send a 'level' parameter containing an empty string. This is
not valid, and AWS will respond to the request saying you cannot
change your own privilege level. Clearly an empty string ("") is
not taken as being 'unchanged', but nil is.

This change detects that an empty string would be sent to AWS and
if so, sends 'nil' in its place (which makes the parameter unset,
and allows the operation). Consequently, this allows the OpsWorks
SetPermissions operation to complete, changing the Sudo or SSH
permissions.

Fixes: hashicorp#458
The ticket is commonly referenced in the CHANGELOG.md file, but this
had not been done.
Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

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

Thank you for sending this PR @charles-at-geospock

This looks functionally good, I just left you some rather stylish and nitpicky comments there. Let me know what you think.

btw. We don't usually touch the Changelog in PRs to avoid conflicts. It is a job of the person merging the PR to do that.

level_aws := aws.String(level_string)
if level_string == "" {
level_aws = nil
}
Copy link
Member

Choose a reason for hiding this comment

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

We have a more idiomatic way of dealing with this exact problem, take a look at d.GetOk()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ta; will fix.

req := &opsworks.SetPermissionInput{
AllowSudo: aws.Bool(d.Get("allow_sudo").(bool)),
AllowSsh: aws.Bool(d.Get("allow_ssh").(bool)),
Level: aws.String(d.Get("level").(string)),
Level: level_aws,
IamUserArn: aws.String(d.Get("user_arn").(string)),
StackId: aws.String(d.Get("stack_id").(string)),
}
Copy link
Member

Choose a reason for hiding this comment

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

The common pattern you can spot elsewhere in the codebase would 1st build the basic request with all required params and then set any optional ones if specified, e.g.

if v, ok := d.GetOk("level"); ok {
    req.Level = aws.String(v.(string))
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a lot cleaner, thanks!

@radeksimko radeksimko added bug Addresses a defect in current functionality. waiting-response Maintainers are waiting on response from community or contributor. labels Jul 3, 2017
The 'GetOk' method makes the assignment of these optional variables
a lot easier.
@charles-at-geospock
Copy link
Contributor Author

charles-at-geospock commented Jul 3, 2017

Changes to the code made as requested; makes things a bit nicer and now I know a little more. I'll look more at other examples of the code in the future to make sure that I can make it more similar.

Did you want the ChangeLog change removing as well? I can strip that out as well, if that would help. And thanks for your very quick response!

Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

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

Thanks for making those enhancements. I removed that line from Changelog and pushed straight to your branch to speed things up. I hope you don't mind.

Pulling in... 🎉

@radeksimko radeksimko merged commit 2a6606e into hashicorp:master Jul 3, 2017
@charles-at-geospock
Copy link
Contributor Author

Awesome, thanks very much. I expect I will be submitting more changes in the future, so I'll try to get those things right in the future and make it smoother all around.

@ghost
Copy link

ghost commented Apr 11, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 11, 2020
@breathingdust breathingdust removed the waiting-response Maintainers are waiting on response from community or contributor. label Sep 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[AWS] aws_opsworks_permission: cannot set permissions for own user
3 participants