Skip to content

Plugins: run registry-named nrc-<command> executables - #27

Open
jansvabik wants to merge 5 commits into
mainfrom
feat/plugins
Open

jansvabik wants to merge 5 commits into
mainfrom
feat/plugins

Conversation

@jansvabik

Copy link
Copy Markdown
Member

Lets a product whose engine ships as its own executable add a command group: norcube <command> … runs nrc-<command> … with the arguments that follow.

Safety

  • Only plugins named in the service registry (services.yaml, new field plugin) ever run; nothing is discovered by a name prefix. The registry refuses a plugin not named nrc-<command>.
  • An executable, or the directory it is in, that other users can write is refused.
  • A protocol handshake (<plugin> __plugin-info → {name, version, protocol}, 5 s limit) comes first; a name or protocol mismatch is refused with a hint about which side to update.
  • Plugins never receive stored credentials: they ask "$NRC_BIN" auth token --audience … for a short-lived token, which works with every sign-in kind and honours profile, org and scopes.

Behaviour

  • Lookup: NORCUBE_PLUGIN_DIR, else <config dir>/norcube/plugins, then PATH.
  • The plugin's exit code passes through (clierr.PassthroughExit); the CLI prints nothing extra. Ctrl-C cancels the plugin, killed after 5 s.
  • Environment: NRC_PLUGIN_PROTOCOL, NRC_BIN, NRC_PROFILE, NRC_ORG, NRC_OUTPUT, NRC_DEBUG.
  • A plugin service may have no endpoint yet; it is then left out of endpoint keys (doctor, --endpoint-url, environments).

Contract: docs/PLUGINS.md. No registry entry uses a plugin yet; the first follows in a separate change.

Tests: internal/plugin (lookup, handshake refusals, writable-by-others refusal, not installed, exit codes), internal/cli (argument and env passthrough, exit code passthrough, not-installed hint), registry validation; full suite passes.

A product whose engine ships as its own executable can add a command group:
norcube <command> runs nrc-<command> from the plugin directory or PATH. Only
plugins named in the service registry run, an executable or directory other
users can write is refused, and a protocol handshake (__plugin-info) comes
first. The plugin's exit code passes through; plugins get tokens from
norcube auth token and never receive stored credentials. Contract in
docs/PLUGINS.md.

Signed-off-by: Jan Švábík <jansvabik@jansvabik.cz>
Signed-off-by: Jan Švábík <jansvabik@jansvabik.cz>
Signed-off-by: Jan Švábík <jansvabik@jansvabik.cz>
Signed-off-by: Jan Švábík <jansvabik@jansvabik.cz>
The --audience names were a hand-kept second copy of the registry's
audiences. They are now derived from it (command, key and aliases), so the
Pentest plugin can get tokens and a new service is one registry entry.
nrc api and doctor consider only services with an endpoint.

Signed-off-by: Jan Švábík <jansvabik@jansvabik.cz>
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