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

[a2-694] Add policy for applications service IAM v1 and v2 #462

Merged
merged 5 commits into from
Jun 5, 2019

Conversation

kmacgugan
Copy link

  • For v1 add resource service_groups
  • For v2 add resource applications:serviceGroups

Signed-off-by: kmacgugan [email protected]

🔩 Description

👍 Definition of Done

👟 Demo Script / Repro Steps

⛓️ Related Resources

✅ Checklist

  • Necessary tests added/updated?
  • Necessary docs added/updated?
  • Code actually executed?
  • Vetting performed (unit tests, lint, etc.)?

- For v1 add resource service_groups
- For v2 add resource applications:serviceGroups

Signed-off-by: kmacgugan <[email protected]>
@susanev
Copy link
Contributor

susanev commented May 31, 2019

do we want any docs changes related to this?
v1: https://automate.chef.io/docs/default-policies/
v2: https://automate.chef.io/docs/iam-v2-api-reference/

should we be updating the viewer and editor iam roles as well?

Copy link
Contributor

@srenatus srenatus left a comment

Choose a reason for hiding this comment

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

Looks good to me. However, I suppose this needs some discussion for IAM v2 -- is this supposed to be accessible out of the box for viewers/editors? If so, it needs to be added to their default policies.

We've recently merged a change that adds these users locally, and upgrades IAM to v2, as part of start_all_services. If you login using viewer or editor (password chefautomate), you can observe the current behaviour, without these additions.

@@ -21,41 +21,41 @@ service ApplicationsService {
// TODO (dan, 2/2019): need to replace this once we have resources and such
Copy link
Contributor

Choose a reason for hiding this comment

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

So can this comment now go away?

@@ -300,6 +300,14 @@ func DefaultPolicies() (map[string]*Policy, error) {
Effect: "allow",
Version: 1,
},
constants.ApplicationsServiceGroupsPolicyID: {
Copy link
Contributor

Choose a reason for hiding this comment

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

You've added this policy to our system policies, which are hidden policies that govern permissions that Automate needs to work correctly (i.e. every user always needs to be able to get the license status so they won't be always blocked by the license modal). These policies never change.

My guess is that we should be able to change permissions on this API. In that case, instead of adding this policy, we'll want to add the API's v2 action to the role(s) that should have access. Maybe Viewer and Editor?

Copy link
Contributor

Choose a reason for hiding this comment

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

actually just kidding about that system policy comment! i misread the code. this is correct for adding a v1 default policy 👍

for v2 permissions:

  1. add applications:* to the Editor role
  2. add applications:serviceGroups:list to the Viewer role
  3. add a datamigration updating those two roles with their new actions (similar to this migration)

Copy link
Contributor

Choose a reason for hiding this comment

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

If we make changes to these roles please also update the iam v2 docs, thx!

option (chef.automate.api.iam.policy).resource = "infra:nodes";
option (chef.automate.api.iam.policy).action = "infra:nodes:list";
option (chef.automate.api.iam.policy).resource = "applications:serviceGroups";
option (chef.automate.api.iam.policy).action = "applications:serviceGroups:list";
Copy link
Contributor

@bcmdarroch bcmdarroch May 31, 2019

Choose a reason for hiding this comment

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

If you can GetServices, can you always get their healthcounts and get services by SG?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, at least you should be able to.

Copy link
Contributor

Choose a reason for hiding this comment

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

gotcha, makes sense that all the resources/actions should be the same then. 👍


INSERT INTO policies
VALUES ('aee14d59-da0b-4974-ba6d-1a018b024874',
'{"action": "*", "effect": "allow", "resource": "applications:serviceGroups", "subjects": ["user:*"]}',
Copy link
Contributor

@bcmdarroch bcmdarroch May 31, 2019

Choose a reason for hiding this comment

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

the resource here must match the v1 resource.

Suggested change
'{"action": "*", "effect": "allow", "resource": "applications:serviceGroups", "subjects": ["user:*"]}',
'{"action": "*", "effect": "allow", "resource": "service_group", "subjects": ["user:*"]}',

-Update v1 policies to actually be v1 policy and not the v2 ones

Signed-off-by: kmacgugan <[email protected]>
@kmacgugan kmacgugan force-pushed the km/applications-policy branch from 2bfa0c1 to 7c7959a Compare May 31, 2019 22:19
@@ -254,6 +255,7 @@ func DefaultRoles() []Role {
"event:*:list",
"ingest:*:get",
"ingest:*:list",
"applications:*:list",
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a possibility there will be an individual getService in the near future? if so we may want to add applications:*:get as well while we're here

SET policy_data='{"action": "list", "effect": "allow", "resource": "service_groups", "subjects": ["user:*"]}',
deletable=TRUE;

UPDATE iam_roles
Copy link
Contributor

Choose a reason for hiding this comment

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

ah i forgot to mention one thing 😅
hopefully last thing to fix: move L13-23 into a new migration file under the postgres/datamigrations/sql directory

Copy link
Contributor

@tylercloke tylercloke left a comment

Choose a reason for hiding this comment

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

Please make the change @bcmdarroch mentioned to the sql migration but otherwise g2g.

Copy link
Contributor

@msorens msorens left a comment

Choose a reason for hiding this comment

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

Generally looks good; three corrections needed.

1,
TRUE)
ON CONFLICT (id) DO UPDATE
SET policy_data='{"action": "list", "effect": "allow", "resource": "service_groups", "subjects": ["user:*"]}',
Copy link
Contributor

Choose a reason for hiding this comment

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

This action must be the same as the action on L5.

@@ -234,6 +234,7 @@ func DefaultRoles() []Role {
"ingest:*",
"secrets:*",
"telemetry:*",
"applications:*",
Copy link
Contributor

Choose a reason for hiding this comment

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

This is incompatible with 45_add_application_policies.up.sql and will result in the entry being added to the database twice. Just delete this line and all is well.

Same for L258 below.

actions = actions || '{applications:*}'
WHERE
id = 'editor';
END;

Choose a reason for hiding this comment

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

What is this END doing that's distinct from COMMIT?

Copy link
Author

Choose a reason for hiding this comment

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

probably i just wanted commit and end snuck in there. Commit will commit a transaction, end just delineates a block of code, like if it were in a loop. I think maybe I copied this structure from a loop somewhere?

kmacgugan added 2 commits June 3, 2019 16:34
@kmacgugan kmacgugan requested a review from a team as a code owner June 4, 2019 00:33
@kmacgugan
Copy link
Author

@susanev I added docs for default policies.

@susanev susanev added the documentation Anything related to the Automate docs. label Jun 4, 2019
};
rpc GetServices(ServicesReq) returns (ServicesRes) {
// TODO (afiune, 4/2019): need to replace this once we have resources and such
// created in the auth system
option (google.api.http).get = "/beta/applications/services";
option (chef.automate.api.policy).resource = "nodes";
option (chef.automate.api.policy).resource = "service_groups";
Copy link

Choose a reason for hiding this comment

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

I don't think this endpoint has anything to do with service-groups here. This is only listing all services so we would probably need a different resource?

Copy link
Contributor

Choose a reason for hiding this comment

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

For any future readers of this, we decided to stick with service_groups because this matches the labeling in the UI, so that is what users will expect to see.

Copy link
Contributor

@mjingle mjingle 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 updating the docs portion! Doc additions looks good to me.

@kmacgugan kmacgugan merged commit 7392f96 into master Jun 5, 2019
@chef-ci chef-ci deleted the km/applications-policy branch June 5, 2019 21:07
@susanev susanev added the auth-team anything that needs to be on the auth team board label Jul 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auth-team anything that needs to be on the auth team board automate-auth documentation Anything related to the Automate docs. eas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants