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-572] Add 'viewer' and 'editor' users to local-dev and dev/acceptance envs, add --skip-policy-migration to upgrade-to-v2 #403

Merged

Conversation

srenatus
Copy link
Contributor

@srenatus srenatus commented May 22, 2019

🔩 Description

Our environments, both for local development and dev/acceptance, are less useful than they could be if everyone keeps using the admin user for all the things. Especially in the short-lived ones, it's cumbersome to add these users manually for acceptance testing time and time again.

The same goes for the local development environment. The world looks quite different if you're not an admin 😉

All of this only applies to envs using IAM v2 or v2.1. However, the users can exist in v1 environments in just the same way, so the local studio env is not upgraded to IAM v2 or IAM v2.1 yet (as of now). ✔️ local studio env is upgrade as well.

Reviewers!

Please follow the commits. There's a few of them, and they should tell the story of this PR 😉

👍 Definition of Done

  • In all used environments (IAM v2 or IAM v2.1), there are these two default users, members of their corresponding teams (team:local:viewers, team:local:editors)
  • the a2-iam-v2-only-integration inspec suite no longer creates the users itself, but relies on the newly added cli command for that
  • there's a (hidden) flag to chef-automate iam upgrade-to-v2, --skip-legacy-upgrade, that causes v1 policies to not get migrated
  • that flag is used for our short-lived dev/acceptance envs
  • that flag is used in start_all_services
  • rename the flag to --skip-policy-migration for clarity (discussed this with @susanev)

👟 Demo Script / Repro Steps

local development

  • rebuild components/automate-cli

  • rebuild components/automate-gateway, rebuild components/authz-service for testing chef-automate iam update-to-v2 --skip-policy-migration

  • start_all_services

  • login as either "viewer" or "editor" (password is "chefautomate")

  • to independently check the --skip-policy-migration flag's output:

[78][default:/src:0]# chef-automate iam reset-to-v1

Reverting to IAM v1 (with pre-upgrade v1 policies)
[79][default:/src:0]# chef-automate iam upgrade-to-v2 --beta2.1 --skip-policy-migration

Enabling IAM v2.1

Skipped policies:
  28 v1 policies
Creating default teams Editors and Viewers...
Skipped: Editors team already exists
Skipped: Viewers team already exists

Migrating existing teams...

Success: Enabled IAM v2.1
[80][default:/src:0]#
  • note that for now, the skip flag is unhidden in the dev env (studio):
[8][default:/src:0]# chef-automate iam upgrade-to-v2 --help
Upgrade to IAM v2 and migrate existing v1 policies. On downgrade, any new v2 policies will be reverted.

Usage:
  chef-automate iam upgrade-to-v2 [flags]

Flags:
      --beta2.1                 Upgrade to version 2.1 with beta project authorization.
  -h, --help                    help for upgrade-to-v2
      --skip-policy-migration   Do not migrate policies from IAM v1.

Global Flags:
  -d, --debug                Enable debug output
      --no-check-version     Disable version check
      --result-json string   Write command result as JSON to PATH
  • to simulate outside-of-dev behaviour, set CHEF_DEV_ENVIRONMENT to something that's not yes:
[80][default:/src:0]# env CHEF_DEV_ENVIRONMENT=no chef-automate iam upgrade-to-v2 --help
Upgrade to IAM v2 and migrate existing v1 policies. On downgrade, any new v2 policies will be reverted.

Usage:
  chef-automate iam upgrade-to-v2 [flags]

Flags:
  -h, --help   help for upgrade-to-v2

Global Flags:
  -d, --debug                Enable debug output
      --no-check-version     Disable version check
      --result-json string   Write command result as JSON to PATH

dev/acceptance envs

  • let's check that post-merge and post-promotion 🤞

⛓️ Related Resources

✅ Checklist

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

@srenatus srenatus requested a review from a team as a code owner May 22, 2019 09:47
@srenatus srenatus self-assigned this May 22, 2019
@srenatus srenatus force-pushed the sr/a2-572/add-default-users-creation-to-automate-cli-dev branch from bae9a81 to 38cca3c Compare May 22, 2019 11:12
@srenatus srenatus changed the title [A2-572] WIP [A2-572] Add 'viewer' and 'editor' users to local-dev and dev/acceptance envs May 22, 2019
@srenatus srenatus changed the title [A2-572] Add 'viewer' and 'editor' users to local-dev and dev/acceptance envs [A2-572] Add 'viewer' and 'editor' users to local-dev and dev/acceptance envs, add --skip-legacy-upgrade to upgrade-to-v2 May 22, 2019
@srenatus srenatus force-pushed the sr/a2-572/add-default-users-creation-to-automate-cli-dev branch 3 times, most recently from 563cdfa to cc93a17 Compare May 22, 2019 15:32
srenatus added 19 commits May 23, 2019 11:29
Reusing the logic we've had for resetting admin access.

Signed-off-by: Stephan Renatus <[email protected]>
This hooks in the call to the new dev command.

The resulting logins will be:

- viewer:chefautomate
- editor:chefautomate

Signed-off-by: Stephan Renatus <[email protected]>
Signed-off-by: Stephan Renatus <[email protected]>
Since this call only happens once (the second time it's run, the
existance of the a2-iamv2-enabled file will block execution), it will
only affect our short-lived environments.

Should we ever re-deploy our long-lived ones, then this _would_ also
skip their legacy policies.  However, I'm not sure why we'd like to
avoid that.

Signed-off-by: Stephan Renatus <[email protected]>
Now, the zero value reflects the current behaviour.

Without this, existing caller (tests!) would have requested the v1
policies to be ignored.

Signed-off-by: Stephan Renatus <[email protected]>
@srenatus srenatus force-pushed the sr/a2-572/add-default-users-creation-to-automate-cli-dev branch from cc93a17 to 8d4e9e7 Compare May 23, 2019 09:33
    git grep skip-legacy-upgrade |\
      gawk -F: '!a[$1]++{ print $1 }' |\
      xargs -- gsed -i s/skip-policy-upgrade/skip-policy-migration/g

Signed-off-by: Stephan Renatus <[email protected]>
@srenatus srenatus force-pushed the sr/a2-572/add-default-users-creation-to-automate-cli-dev branch from 8d4e9e7 to 61ccc53 Compare May 23, 2019 09:35
@srenatus srenatus changed the title [A2-572] Add 'viewer' and 'editor' users to local-dev and dev/acceptance envs, add --skip-legacy-upgrade to upgrade-to-v2 [A2-572] Add 'viewer' and 'editor' users to local-dev and dev/acceptance envs, add --skip-policy-migration to upgrade-to-v2 May 23, 2019
@srenatus srenatus removed the WIP label May 23, 2019
}

// all flags are hidden right now
cmd.PersistentFlags().VisitAll(func(f *pflag.Flag) { f.Hidden = !isDevMode() })
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought the team consensus was that skip-policy-migration was for public consumption as well...?

Copy link
Contributor

Choose a reason for hiding this comment

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

i believe that consensus convo happened last friday during subtasking and i wasnt there. if we do make it public we should have a corresponding docs update, so id like to do that in a separate pr if possible.

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'm all in favour of not adding anything here 😉

recordFailure()
return nil, status.Errorf(codes.Internal, "list v1 policies: %s", err.Error())
}
reports = append(reports, fmt.Sprintf("%d v1 policies", len(pols)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider "%d v1 policies found -- skipping"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The output, in the end, will be

[79][default:/src:0]# chef-automate iam upgrade-to-v2 --beta2.1 --skip-policy-migration

Enabling IAM v2.1

Skipped policies:
  28 v1 policies

(see PR message) -- I'd rather not use skipped twice there

Copy link
Contributor

@susanev susanev May 23, 2019

Choose a reason for hiding this comment

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

@srenatus do you mind if we have a single line with Skipped: %d v1 policies, then a newline before the teams output?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now, that's shared between a migration and no migration (see https://github.com/chef/a2/pull/4120#issuecomment-433389839), so it's a little more work than just the formatting. But yeah, we can do that.

Copy link
Contributor

@susanev susanev May 23, 2019

Choose a reason for hiding this comment

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

oh i see.... nah, just leave it as is for now.

return err
}
// Note: the teams SHOULD exist. But since you never know what happens in a
// long running acceptance env, we'll better ensure them:
Copy link
Contributor

Choose a reason for hiding this comment

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

s/we'll/we'd/

"editor": {"Editor User", "chefautomate", "editors"},
} {
userID, _, err := adminmgmt.CreateUserOrUpdatePassword(ctx,
apiClient, username, data.displayName, data.password, false /* dry run */)
Copy link
Contributor

Choose a reason for hiding this comment

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

Personal style thing for sure, but just my 2 cents:
false /* dry run */ suggests to me that "setting this param false here and that means it is a dry run".
Whereas:
/* dry run */ false suggests to me that "this is supplying a value of false for 'dry run' and that means it is not a dry run.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hehe I didn't mean to convey that much -- I really just meant "this bool is the dry run parameter". But yeah, you're not wrong with that connotation 😉

touch /root/a2-iamv2-enabled
;;
"v2")
chef-automate iam upgrade-to-v2
chef-automate iam upgrade-to-v2 --skip-policy-migration
chef-automate dev create-iam-dev-users
Copy link
Contributor

Choose a reason for hiding this comment

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

Good stuff!

@srenatus
Copy link
Contributor Author

I'll merge this on Monday and deal with the fallout.

@srenatus srenatus merged commit 99e3425 into master May 27, 2019
@chef-ci chef-ci deleted the sr/a2-572/add-default-users-creation-to-automate-cli-dev branch May 27, 2019 06:26
@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 studio-dev
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants