Skip to content

entries: access rules on an entry and on each protocol (draft, after #294) - #320

Draft
jseifeddine wants to merge 5 commits into
sol1:mainfrom
jseifeddine:feat/entry-access-rules
Draft

jseifeddine wants to merge 5 commits into
sol1:mainfrom
jseifeddine:feat/entry-access-rules

Conversation

@jseifeddine

Copy link
Copy Markdown
Contributor

Draft: waiting on #294 (permissions and custom roles). Stacked on #299.

This PR has the entry- and protocol-level access rules that were split out of #299, as suggested in the review there. It has one commit of its own, entries: access rules on an entry and on each protocol, on top of #299's branch. Until #299 merges, GitHub also shows #299's commits here.

What it adds

Optional allowed_groups / allowed_users on the host and on each protocol of a multi-protocol entry. They use the same form and matching as a folder .config, and only narrow access inside the folder. Admins bypass them.

Host Protocol Host visible Protocol visible
Allow Allow yes yes
Allow Deny yes, while another protocol is usable no
Deny Allow yes yes
Deny Deny no no
  • A protocol's own rule wins over the host's, and the host's rule applies to protocols without one.
  • The server filters wherever entries leave it: listings, /api/addressbook, the search index, the credential variable list, connect and /api/connect. A protocol a user may not use is answered as if it did not exist.
  • The editor has allowed groups and users in the Host box, and an optional rule of its own for each protocol. Rules are shown only to admins.

Fixed from the #299 review

  • An entry created with an access rule was stored in the flat form, so an older instance sharing the Vault read it and ignored the rule. prepare_entry_body now converts a flat body with a rule to the list form before compact(), which older instances cannot read. Every write path (POST, PUT, ?move=true) goes through it. A test sends the flat body a script or the NetBox webhook would send.

Open items, to settle with #294

  • A body that omits the rules clears them. A NetBox webhook PUT, which sends no rules, drops rules an admin set in the UI. They should be kept when omitted, as external_id is. That needs a way to clear a rule on purpose: today the editor leaves out an empty rule and the server stores an empty host rule as absent. I'd rather settle that together with how Design: permissions and custom roles #294 handles access than patch it here.
  • Where rules live. Design: permissions and custom roles #294 keeps folder access separate from roles and lists per-folder permissions as out of scope. If per-entry rules are wanted at all, they probably belong in that design.

Testing

On top of #299: cargo clippy --all-targets -- -D warnings is clean, and cargo test passes 455 tests. The two vault::tests::test_build_client_mtls_* tests fail, the same as on unchanged main in this container (UnsupportedCertVersion). Playwright: 92/92.

A machine reached over more than one protocol needed one entry per
protocol, with the hostname, display name and credentials
copied between them. An entry can now hold a list of protocols.

The entry's own fields are the host's defaults. Each item in
`protocols` inherits them and sets only what differs; an empty value
clears an inherited one, and `port` is never inherited. The first
protocol is the primary. An optional `name` tells two protocols of the
same type apart.

- Existing flat entries are read as one protocol and connect exactly as
  before. An entry is stored in the flat form whenever that loses
  nothing, so older instances keep reading it, and the write API still
  accepts the flat body, including the NetBox webhook's.
- Connecting resolves host and protocol to one flat entry, so folder
  defaults, credential variables, recording and the rest apply per
  protocol unchanged. Credentials come from the protocol, then the
  host, then the folder's defaults for that type.
- The connect endpoint and `/api/connect` take an optional `protocol`
  (a name, or a type), defaulting to the primary. Sessions and
  recordings record the protocol they used.
- Updates keep stored secrets per protocol, matched by name.
- Connections: the editor has a Host section and a tab per protocol.
  The list shows a badge per protocol, the primary first, folding the
  rest into a +N chip. Connect is a split button whose menu lists every
  protocol, the primary marked as default.
- Docs: entries in api.md, a multi-protocol NetBox webhook in
  netbox.md, and an upgrade note in migration.md.

Refs sol1#296
The Type cell of an entry with several protocols kept to two lines and
hid the rest behind a +N chip, so seeing them all took a hover or the
Connect menu. It now shows a badge for every protocol, the primary
first, and wraps onto as many lines as it needs.

Refs sol1#296
An update keeps each protocol's stored secrets by matching names, so a
protocol renamed through the API lost its password or key. The editor
does not allow renaming, but an API client or script can.

A protocol in an update body can now name its old name in
`renamed_from`, and its stored secrets move with it to the new name.
It is used for that update only and never stored or returned; a
malformed one is refused like a malformed name.

Refs sol1#296
An ad-hoc connection is one protocol to one host. A body with a
`protocols` list failed with "unknown session type", since it has no
top-level type; it now says what is wrong.

Refs sol1#296
Optional `allowed_groups` / `allowed_users` on the host and on each
protocol narrow access inside the folder, in the same form as a folder
`.config`. The folder stays the boundary; admins bypass them.

- A protocol's own rule wins over the host's, and the host's applies to
  protocols without one. An entry is listed while one of its protocols
  is usable, and lists only those.
- Listings, search, the credential variable list, the connect endpoint
  and `/api/connect` all filter on the server. A protocol a user may
  not use answers as if it did not exist.
- An entry with a rule is always stored in the list form, which older
  instances cannot read, so they leave it out rather than ignore the
  rule. A flat body with a rule, as a script or the NetBox webhook
  would send it, is converted before it is stored.
- Editor: allowed groups and users in the Host box, and an own rule per
  protocol. The rules are shown only to admins.

Split from the multi-protocol entries change, to be settled with the
permissions design in sol1#294.

Refs sol1#296
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