Skip to content

client: allow ACL to be provided at key creation via -acl flag - #127

Open
AneesPatel wants to merge 1 commit into
pinterest:masterfrom
AneesPatel:create-with-acl
Open

client: allow ACL to be provided at key creation via -acl flag#127
AneesPatel wants to merge 1 commit into
pinterest:masterfrom
AneesPatel:create-with-acl

Conversation

@AneesPatel

Copy link
Copy Markdown

Currently knox create always creates keys with an empty ACL, so applying
access controls is a two-step workflow: knox create, then
knox access -acl <file> <key>. Between those two steps the key exists
without its intended access controls. This PR resolves the
TODO(devinlundberg): allow ACL to be entered as input in
client/create.go by letting the ACL be supplied at creation time:

knox create -acl acl.json my_service:my_key

-acl takes a JSON file containing a list of access rules, in the exact
same format already accepted by knox access -acl. When the flag is
omitted, behavior is unchanged (empty ACL).

Changes

  • Extracted the ACL file read/parse logic from runUpdateAccess into a
    shared parseACLFile helper, now used by both knox access -acl and
    knox create -acl. No behavior change for knox access.
  • Added the -acl flag to knox create. The ACL file is parsed before
    key data is read from stdin, so an unreadable or malformed file fails
    fast without first consuming the user's secret. Unreadable files and
    invalid JSON return user-facing (non-server) errors, consistent with the
    existing input validation in the command.
  • Updated knox create usage and help text to document the flag.

Tests

  • TestParseACLFile: table-driven coverage of a valid ACL file, a missing
    file, and malformed JSON.
  • TestRunCreateACL: table-driven coverage of runCreate against a mock
    server, verifying that no flag still sends an empty ACL ([]), that a
    provided ACL file is parsed and sent on the wire, and that a missing file
    yields a non-server error.

All of go build ./..., go vet ./..., gofmt -d -s ., and
go test ./... pass.

Adds an -acl flag to `knox create` that accepts a JSON file of access
rules (same format as `knox access -acl`), so a key can be created with
its intended ACL in one step instead of a follow-up `knox access` call.
The shared parseACLFile helper is extracted from updateaccess.go and used
by both commands. Resolves the TODO in client/create.go.
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.

1 participant