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

feat: implement Service Account / Local Users #3215

Merged
merged 4 commits into from
Mar 17, 2020

Conversation

alexmt
Copy link
Collaborator

@alexmt alexmt commented Mar 10, 2020

Closes #3185
Closes #2108
Closes #3221

PR introduces local users support in Argo CD.

  • API changes
  • CLI changes
  • Unit Tests
  • UI
  • E2E Tests
  • Docs

CLI commands

  • List existing accounts:
argocd account list                                                                                                                                                      NAME   ENABLED  CAPABILITIES
admin  true     apiKey, login
test   true     apiKey
  • get account details:
Name:               admin
Enabled:            true
Capabilities:       apiKey, login

Tokens:
ID                                    ISSUED AT                  EXPIRING AT
2b8174fb-5e67-4f34-80d8-511f91422a6a  2020-03-09T14:31:25-07:00  never
c4f53804-0182-4021-b502-09a947f0488f  2020-03-09T14:26:34-07:00  2020-03-09T14:26:34-07:00 (expired)
  • generate token for an account:
argocd account generate-token --account test
xxxxxxxxxxxxxxxxxxxxx
  • delete existing account token:
argocd account delete-token 2b8174fb-5e67-4f34-80d8-511f91422a6a
  • change local user password:
 argocd account update-password --account <name> --current-password <current-user-password> --new-password <new-password-for-localuser>

UI

image

image

image

@alexmt alexmt requested a review from jessesuen March 10, 2020 01:29
util/settings/settings_test.go Outdated Show resolved Hide resolved
util/settings/settings.go Show resolved Hide resolved
util/settings/settings.go Show resolved Hide resolved
util/settings/accounts_test.go Show resolved Hide resolved
cmd/argocd/commands/account.go Outdated Show resolved Hide resolved
server/account/account.go Outdated Show resolved Hide resolved
@alexmt alexmt force-pushed the 3185-local-users branch 2 times, most recently from 5b1e3db to 148e925 Compare March 10, 2020 02:51
@codecov
Copy link

codecov bot commented Mar 10, 2020

Codecov Report

Merging #3215 into master will increase coverage by 0.17%.
The diff coverage is 41.39%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3215      +/-   ##
==========================================
+ Coverage   38.81%   38.99%   +0.17%     
==========================================
  Files         169      172       +3     
  Lines       18321    18764     +443     
  Branches      272      237      -35     
==========================================
+ Hits         7112     7317     +205     
- Misses      10333    10540     +207     
- Partials      876      907      +31     
Impacted Files Coverage Δ
cmd/argocd/commands/account.go 0.00% <0.00%> (ø)
ui/src/app/shared/models.ts 100.00% <ø> (ø)
util/settings/settings.go 38.72% <11.11%> (+0.81%) ⬆️
util/session/sessionmanager.go 55.94% <55.55%> (-2.46%) ⬇️
ui/src/app/shared/services/accounts-service.ts 58.33% <58.33%> (ø)
server/account/account.go 63.02% <69.69%> (+19.27%) ⬆️
util/settings/accounts.go 73.33% <73.33%> (ø)
server/project/project.go 59.43% <100.00%> (ø)
server/rbacpolicy/rbacpolicy.go 80.30% <100.00%> (+0.61%) ⬆️
server/server.go 57.59% <100.00%> (ø)
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 42d5723...0addefc. Read the comment docs.

@alexmt alexmt force-pushed the 3185-local-users branch 3 times, most recently from cccec64 to 1f400db Compare March 10, 2020 20:25
@alexmt alexmt marked this pull request as ready for review March 10, 2020 21:22
@alexmt alexmt requested a review from jannfis March 17, 2020 00:31
Copy link
Member

@jannfis jannfis left a comment

Choose a reason for hiding this comment

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

Wow, awesome work. Looks good to me so far, I have some minor comments see below.

Comment on lines 263 to 265
Use: "get",
Short: "Get account details",
Example: "argocd account get",
Copy link
Member

Choose a reason for hiding this comment

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

IMHO should provide information on the argument the command optional takes - i.e. the account name. Also should be made clear in the example that with no parameters, current account will be get, and if parameter given, information for named account will be retrieved.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agree. Updated example of all commands that defaults to the current account.

Comment on lines 329 to 331
Use: "generate-token",
Short: "Generate account token",
Example: "argocd account generate-token",
Copy link
Member

Choose a reason for hiding this comment

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

Same as above, information about the arguments should be given.

Comment on lines 360 to 362
Use: "delete-token",
Short: "Deletes account token",
Example: "argocd account delete-token ID",
Copy link
Member

Choose a reason for hiding this comment

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

Here as well - more information about the parameters, please.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@@ -38,8 +38,6 @@ const (

// Default paths on the pod's file system
const (
// The default base path where application config is located
DefaultPathAppConfig = "/app/config"
Copy link
Member

Choose a reason for hiding this comment

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

Hm, is this not used anywhere?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, look like we forgot to delete it after some refactoring.

@@ -28,39 +30,49 @@ type Server struct {
// NewServer returns a new instance of the Session service
func NewServer(sessionMgr *session.SessionManager, settingsMgr *settings.SettingsManager, enf *rbac.Enforcer) *Server {
return &Server{sessionMgr, settingsMgr, enf}

}

// UpdatePassword updates the password of the local admin superuser.
Copy link
Member

Choose a reason for hiding this comment

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

This comment should be adapted to reflect reality. Probably there are more

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 94 to 96
rpc GetAccount(GetAccountRequest) returns (Account) {
option (google.api.http).get = "/api/v1/account/{name}";
}
Copy link
Member

Choose a reason for hiding this comment

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

Indentation

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

return &s
}

// Create creates a new token for a given subject (user) and returns it as a string.
// Passing a value of `0` for secondsBeforeExpiry creates a token that never expires.
func (mgr *SessionManager) Create(subject string, secondsBeforeExpiry int64) (string, error) {
func (mgr *SessionManager) Create(subject string, secondsBeforeExpiry int64, id string) (string, error) {
Copy link
Member

Choose a reason for hiding this comment

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

We should clarify what id is used for here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done. Updated comment

@@ -0,0 +1,307 @@
package settings
Copy link
Member

Choose a reason for hiding this comment

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

General thought on this package - I think all Public methods and types should be rather well commented.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agree. Added missing comments

}

func parseAdminAccount(secret *v1.Secret, cm *v1.ConfigMap) (*Account, error) {
adminAccount := &Account{Enabled: true, Capabilities: []AccountCapability{AccountCapabilityApiKey, AccountCapabilityLogin}}
Copy link
Member

Choose a reason for hiding this comment

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

Hm, do we really want to allow admin account access to API by default? Or is that for backwards compatibility? If so, we should make a deprecation notice, that admin access to API will be disabled from v2 onwards or something similar.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nice catch. Admin account should not be able to generate API keys by default. That functionality does not exist before 1.5 so we are not breaking backward compatibility. Updated the default capabilities.

@@ -0,0 +1,67 @@
package settings
Copy link
Member

Choose a reason for hiding this comment

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

General thought on this test package. I think we should also test for bad/malformed input data, that would also come up with more code coverage.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done. Added missing tests

@alexmt
Copy link
Collaborator Author

alexmt commented Mar 17, 2020

Thank you for review @jannfis ! PTAL

Copy link
Member

@jannfis jannfis left a comment

Choose a reason for hiding this comment

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

LGTM

@alexmt alexmt merged commit 3c2be61 into argoproj:master Mar 17, 2020
@alexmt alexmt deleted the 3185-local-users branch March 17, 2020 22:31
@alex1989hu
Copy link

@alexmt: thanks for the documentation part

@omerlh
Copy link

omerlh commented Mar 25, 2020

Something unclear to me - look like you can define a token in the config map (by looking on the PR), but how can you use this token? What defined in the PR is claims, how can I sign it?

@alexmt
Copy link
Collaborator Author

alexmt commented Mar 26, 2020

hello @omerlh ,

User copy generated token and use it same as token generated during normal login process. Only token id, issuedAt and expiringAt time fields are stored in secret. This allows user to know when the token is going to expire and revoke it if necessary

@omerlh
Copy link

omerlh commented Apr 2, 2020

So there is no declarative way to create tokens? only using the CLI?

for i := range a.Capabilities {
items = append(items, string(a.Capabilities[i]))
}
return strings.Join(items, ",")

Choose a reason for hiding this comment

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

This results in "apiKey, login" getting turned into "apiKey,login"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants