Documentation
¶
Index ¶
- Variables
- func Routes(s *server.Server) []server.Route
- type CreateRequest
- type DeleteRequest
- type ListRequest
- type UserSshkeyCollectionResponse
- type UserSshkeyCreateRequest
- type UserSshkeyCreateResponse
- type UserSshkeyDeleteRequest
- type UserSshkeyDeleteResponse
- type UserSshkeyKey
- type UserSshkeyResult
Constants ¶
This section is empty.
Variables ¶
var Group = endpoint.Define( "sshkey", "The authorized SSH keys of a user", endpoint.Area(area.Security), endpoint.Prefix("node/{hostname}/user/{name}"), endpoint.Uses[dispatch.Deps](), endpoint.Tag("sshkey_operations", "User SSH key", "The authorized SSH keys of a user"), endpoint.CommandNotes("The [sshkey behavior](../../../../../../reference/behaviors/security/user/sshkey/sshkey.md) page tells where the behavior runs, what it is built on and its settings."), endpoint.Doc[types.RowStatus](dispatch.RowStatusDoc), endpoint.Get[ListRequest, UserSshkeyCollectionResponse]("list"). Handle(HandleList). ID("GetNodeUserSshkey"). Describe("List the authorized SSH keys of a user"). Permission("user:read"). Returns("Each target host's result."). Explain("Reads ~/.ssh/authorized_keys of the user through gohai, with the type, the SHA256 fingerprint, the comment and the options of each key. A user with no file has no keys. A user that the host does not have is not found."). Example("--target web-01 --name osapitest", "A user with keys"). Example("--target web-01 --name osapitest", "A user with no keys"). Example("--target web-01 --name osapitest", "A host key that gohai cannot read"). Result("A user with keys, on one host:\n\n```ansi\n$ osapi client node user sshkey list --target web-01 --name osapitest\n\x1b[1;38;2;0;213;255mResults:\x1b[0m\n \x1b[38;2;10;143;176mHOSTNAME \x1b[0m\x1b[38;2;10;143;176mSTATUS \x1b[0m\x1b[38;2;10;143;176mTYPE \x1b[0m\x1b[38;2;10;143;176mFINGERPRINT \x1b[0m\x1b[38;2;10;143;176mCOMMENT \x1b[0m\x1b[38;2;10;143;176mOPTIONS\x1b[0m\n \x1b[1mweb-01\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m \x1b[1mssh-ed25519\x1b[0m SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk osapitest@example \n \x1b[38;2;138;138;138mweb-01\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m \x1b[1mssh-ed25519\x1b[0m SHA256:a5CeY6Lh3ZXkJOqGyuwb24kQeVjgag1gc9ujzv++nhE other@example from=\"10.0.0.0/8\"\n\n 1 host: \x1b[38;2;103;234;147m1 ok\x1b[0m \x1b[38;2;138;138;138mjob 550e8400-e29b-41d4-a716-446655440000\x1b[0m \x1b[38;2;138;138;138mtrace 26e448c9dbe1c4a8d216a98c675079c9\x1b[0m\n```\n\nOn each host, where one cannot run it:\n\n```ansi\n$ osapi client node user sshkey list --target _all --name osapitest\n\x1b[1;38;2;0;213;255mResults:\x1b[0m\n \x1b[38;2;10;143;176mHOSTNAME \x1b[0m\x1b[38;2;10;143;176mSTATUS \x1b[0m\x1b[38;2;10;143;176mTYPE \x1b[0m\x1b[38;2;10;143;176mFINGERPRINT \x1b[0m\x1b[38;2;10;143;176mCOMMENT \x1b[0m\x1b[38;2;10;143;176mOPTIONS\x1b[0m\n \x1b[1mweb-01\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m \x1b[1mssh-ed25519\x1b[0m SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk osapitest@example \n \x1b[38;2;138;138;138mweb-01\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m \x1b[1mssh-ed25519\x1b[0m SHA256:a5CeY6Lh3ZXkJOqGyuwb24kQeVjgag1gc9ujzv++nhE other@example from=\"10.0.0.0/8\"\n \x1b[1mweb-02\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m \x1b[1mssh-ed25519\x1b[0m SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk osapitest@example \n \x1b[38;2;138;138;138mweb-02\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m \x1b[1mssh-ed25519\x1b[0m SHA256:a5CeY6Lh3ZXkJOqGyuwb24kQeVjgag1gc9ujzv++nhE other@example from=\"10.0.0.0/8\"\n\n 3 hosts: \x1b[38;2;103;234;147m2 ok\x1b[0m, \x1b[38;5;222m1 skipped\x1b[0m \x1b[38;2;138;138;138mjob 550e8400-e29b-41d4-a716-446655440000\x1b[0m \x1b[38;2;138;138;138mtrace 26e448c9dbe1c4a8d216a98c675079c9\x1b[0m\n\n\x1b[1;38;2;255;0;255mDetails:\x1b[0m\n \x1b[1mmac-01\x1b[0m \x1b[38;5;222mskipped\x1b[0m operation not supported on this OS family\n```\n\nWith `--json`, the API's response:\n\n```json\n{\n \"job_id\": \"550e8400-e29b-41d4-a716-446655440000\",\n \"results\": [\n {\n \"comment\": \"osapitest@example\",\n \"fingerprint\": \"SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk\",\n \"hostname\": \"web-01\",\n \"status\": \"ok\",\n \"type\": \"ssh-ed25519\"\n },\n {\n \"comment\": \"other@example\",\n \"fingerprint\": \"SHA256:a5CeY6Lh3ZXkJOqGyuwb24kQeVjgag1gc9ujzv++nhE\",\n \"hostname\": \"web-01\",\n \"options\": \"from=\\\"10.0.0.0/8\\\"\",\n \"status\": \"ok\",\n \"type\": \"ssh-ed25519\"\n }\n ]\n}\n```\n\nA user with no keys, on one host:\n\n```ansi\n$ osapi client node user sshkey list --target web-01 --name osapitest\n\x1b[1;38;2;0;213;255mResults:\x1b[0m\n \x1b[38;2;138;138;138mNone.\x1b[0m\n```\n\nOn each host, where one cannot run it:\n\n```ansi\n$ osapi client node user sshkey list --target _all --name osapitest\n\x1b[1;38;2;0;213;255mResults:\x1b[0m\n\n 1 host: \x1b[38;5;222m1 skipped\x1b[0m \x1b[38;2;138;138;138mjob 550e8400-e29b-41d4-a716-446655440000\x1b[0m \x1b[38;2;138;138;138mtrace 26e448c9dbe1c4a8d216a98c675079c9\x1b[0m\n\n\x1b[1;38;2;255;0;255mDetails:\x1b[0m\n \x1b[1mmac-01\x1b[0m \x1b[38;5;222mskipped\x1b[0m operation not supported on this OS family\n```\n\nWith `--json`, the API's response:\n\n```json\n{\n \"job_id\": \"550e8400-e29b-41d4-a716-446655440000\",\n \"results\": []\n}\n```\n\nA host key that gohai cannot read, on one host:\n\n```ansi\n$ osapi client node user sshkey list --target web-01 --name osapitest\n\x1b[1;38;2;0;213;255mResults:\x1b[0m\n \x1b[38;2;10;143;176mHOSTNAME \x1b[0m\x1b[38;2;10;143;176mSTATUS \x1b[0m\x1b[38;2;10;143;176mTYPE \x1b[0m\x1b[38;2;10;143;176mFINGERPRINT \x1b[0m\x1b[38;2;10;143;176mCOMMENT \x1b[0m\x1b[38;2;10;143;176mOPTIONS\x1b[0m\n \x1b[1mweb-01\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m \x1b[1mssh-ed25519\x1b[0m SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk osapitest@example \n\n 1 host: \x1b[38;2;103;234;147m1 ok\x1b[0m \x1b[38;2;138;138;138mjob 550e8400-e29b-41d4-a716-446655440000\x1b[0m \x1b[38;2;138;138;138mtrace 26e448c9dbe1c4a8d216a98c675079c9\x1b[0m\n```\n\nOn each host, where one cannot run it:\n\n```ansi\n$ osapi client node user sshkey list --target _all --name osapitest\n\x1b[1;38;2;0;213;255mResults:\x1b[0m\n \x1b[38;2;10;143;176mHOSTNAME \x1b[0m\x1b[38;2;10;143;176mSTATUS \x1b[0m\x1b[38;2;10;143;176mTYPE \x1b[0m\x1b[38;2;10;143;176mFINGERPRINT \x1b[0m\x1b[38;2;10;143;176mCOMMENT \x1b[0m\x1b[38;2;10;143;176mOPTIONS\x1b[0m\n \x1b[1mweb-01\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m \x1b[1mssh-ed25519\x1b[0m SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk osapitest@example \n \x1b[1mweb-02\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m \x1b[1mssh-ed25519\x1b[0m SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk osapitest@example \n\n 3 hosts: \x1b[38;2;103;234;147m2 ok\x1b[0m, \x1b[38;5;222m1 skipped\x1b[0m \x1b[38;2;138;138;138mjob 550e8400-e29b-41d4-a716-446655440000\x1b[0m \x1b[38;2;138;138;138mtrace 26e448c9dbe1c4a8d216a98c675079c9\x1b[0m\n\n\x1b[1;38;2;255;0;255mDetails:\x1b[0m\n \x1b[1mmac-01\x1b[0m \x1b[38;5;222mskipped\x1b[0m operation not supported on this OS family\n```\n\nWith `--json`, the API's response:\n\n```json\n{\n \"job_id\": \"550e8400-e29b-41d4-a716-446655440000\",\n \"results\": [\n {\n \"comment\": \"osapitest@example\",\n \"fingerprint\": \"SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk\",\n \"hostname\": \"web-01\",\n \"status\": \"ok\",\n \"type\": \"ssh-ed25519\"\n }\n ]\n}\n```\n\nThe command fails in these cases:\n\n| Call | Flags | Fails with |\n| --- | --- | --- |\n| A user that the host does not have | `--name nobody` | not found |\n| A name that is not a user name | `--name \"Bad;name\"` | Name |\n| A name over 32 characters | `--name aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` | max |"). Errors(endpoint.NotFound(behavior.ErrNotFound, "The host does not have what the request names, such as the object of a deploy."), endpoint.Conflict(behavior.ErrNotManaged, "osapi did not deploy the item, so it does not change it, or the host does not have a program that the method needs.").Because(types.ReasonNotManaged), endpoint.Conflict(behavior.ErrNotInstalled, "osapi did not deploy the item, so it does not change it, or the host does not have a program that the method needs.").Because(types.ReasonNotInstalled), endpoint.Invalid(dispatch.ErrInvalid, "The request is not valid, or the host refuses the input, such as a path that is a directory.")), endpoint.Post[CreateRequest, UserSshkeyCreateResponse]("create"). Handle(HandleCreate). ID("PostNodeUserSshkey"). Describe("Add an authorized SSH key to a user"). Permission("user:write"). Returns("Each target host's result, with whether it changed."). Explain("Adds the key line to the end of ~/.ssh/authorized_keys of the user, and makes the directory and the file if they are missing, with modes 700 and 600, owned by the user. A key that the file has already, by its fingerprint, does not change it. A line with no public key is refused. A user that the host does not have is not found. It runs on the Debian family only, and elsewhere reports skipped."). Example("--target web-01 --name osapitest --key \"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJl85dcLw7lIdX+IyXEXT00CTCezv/2E1jvolleleo6Z osapitest@example\"", "Add a key"). Example("--target web-01 --name osapitest --key \"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGLPeEZQDbhOrSIx6gISjxXIcREV3rwL517pX6m9G5jc other@example\"", "Add a second key"). Example("--target web-01 --name osapitest --key \"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGLPeEZQDbhOrSIx6gISjxXIcREV3rwL517pX6m9G5jc other@example\"", "A key after a last line with no line break"). Example("--target web-01 --name osapitest --key \"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJl85dcLw7lIdX+IyXEXT00CTCezv/2E1jvolleleo6Z osapitest@example\"", "A key the user has"). Result("Add a key, on one host:\n\n```ansi\n$ osapi client node user sshkey create --target web-01 --name osapitest --key \"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJl85dcLw7lIdX+IyXEXT00CTCezv/2E1jvolleleo6Z osapitest@example\"\n\x1b[1;38;2;0;213;255mResults:\x1b[0m\n \x1b[38;2;10;143;176mHOSTNAME \x1b[0m\x1b[38;2;10;143;176mSTATUS \x1b[0m\x1b[38;2;10;143;176mFINGERPRINT\x1b[0m\n \x1b[1mweb-01\x1b[0m \x1b[38;2;103;234;147mchanged\x1b[0m SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk\n\n 1 host: \x1b[38;2;103;234;147m1 changed\x1b[0m \x1b[38;2;138;138;138mjob 550e8400-e29b-41d4-a716-446655440000\x1b[0m \x1b[38;2;138;138;138mtrace 26e448c9dbe1c4a8d216a98c675079c9\x1b[0m\n```\n\nOn each host, where one cannot run it:\n\n```ansi\n$ osapi client node user sshkey create --target _all --name osapitest --key \"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJl85dcLw7lIdX+IyXEXT00CTCezv/2E1jvolleleo6Z osapitest@example\"\n\x1b[1;38;2;0;213;255mResults:\x1b[0m\n \x1b[38;2;10;143;176mHOSTNAME \x1b[0m\x1b[38;2;10;143;176mSTATUS \x1b[0m\x1b[38;2;10;143;176mFINGERPRINT\x1b[0m\n \x1b[1mweb-01\x1b[0m \x1b[38;2;103;234;147mchanged\x1b[0m SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk\n \x1b[1mweb-02\x1b[0m \x1b[38;2;103;234;147mchanged\x1b[0m SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk\n\n 3 hosts: \x1b[38;2;103;234;147m2 changed\x1b[0m, \x1b[38;5;222m1 skipped\x1b[0m \x1b[38;2;138;138;138mjob 550e8400-e29b-41d4-a716-446655440000\x1b[0m \x1b[38;2;138;138;138mtrace 26e448c9dbe1c4a8d216a98c675079c9\x1b[0m\n\n\x1b[1;38;2;255;0;255mDetails:\x1b[0m\n \x1b[1mmac-01\x1b[0m \x1b[38;5;222mskipped\x1b[0m operation not supported on this OS family\n```\n\nWith `--json`, the API's response:\n\n```json\n{\n \"job_id\": \"550e8400-e29b-41d4-a716-446655440000\",\n \"results\": [\n {\n \"changed\": true,\n \"fingerprint\": \"SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk\",\n \"hostname\": \"web-01\",\n \"status\": \"ok\"\n }\n ]\n}\n```\n\nAdd a second key, on one host:\n\n```ansi\n$ osapi client node user sshkey create --target web-01 --name osapitest --key \"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGLPeEZQDbhOrSIx6gISjxXIcREV3rwL517pX6m9G5jc other@example\"\n\x1b[1;38;2;0;213;255mResults:\x1b[0m\n \x1b[38;2;10;143;176mHOSTNAME \x1b[0m\x1b[38;2;10;143;176mSTATUS \x1b[0m\x1b[38;2;10;143;176mFINGERPRINT\x1b[0m\n \x1b[1mweb-01\x1b[0m \x1b[38;2;103;234;147mchanged\x1b[0m SHA256:a5CeY6Lh3ZXkJOqGyuwb24kQeVjgag1gc9ujzv++nhE\n\n 1 host: \x1b[38;2;103;234;147m1 changed\x1b[0m \x1b[38;2;138;138;138mjob 550e8400-e29b-41d4-a716-446655440000\x1b[0m \x1b[38;2;138;138;138mtrace 26e448c9dbe1c4a8d216a98c675079c9\x1b[0m\n```\n\nOn each host, where one cannot run it:\n\n```ansi\n$ osapi client node user sshkey create --target _all --name osapitest --key \"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGLPeEZQDbhOrSIx6gISjxXIcREV3rwL517pX6m9G5jc other@example\"\n\x1b[1;38;2;0;213;255mResults:\x1b[0m\n \x1b[38;2;10;143;176mHOSTNAME \x1b[0m\x1b[38;2;10;143;176mSTATUS \x1b[0m\x1b[38;2;10;143;176mFINGERPRINT\x1b[0m\n \x1b[1mweb-01\x1b[0m \x1b[38;2;103;234;147mchanged\x1b[0m SHA256:a5CeY6Lh3ZXkJOqGyuwb24kQeVjgag1gc9ujzv++nhE\n \x1b[1mweb-02\x1b[0m \x1b[38;2;103;234;147mchanged\x1b[0m SHA256:a5CeY6Lh3ZXkJOqGyuwb24kQeVjgag1gc9ujzv++nhE\n\n 3 hosts: \x1b[38;2;103;234;147m2 changed\x1b[0m, \x1b[38;5;222m1 skipped\x1b[0m \x1b[38;2;138;138;138mjob 550e8400-e29b-41d4-a716-446655440000\x1b[0m \x1b[38;2;138;138;138mtrace 26e448c9dbe1c4a8d216a98c675079c9\x1b[0m\n\n\x1b[1;38;2;255;0;255mDetails:\x1b[0m\n \x1b[1mmac-01\x1b[0m \x1b[38;5;222mskipped\x1b[0m operation not supported on this OS family\n```\n\nWith `--json`, the API's response:\n\n```json\n{\n \"job_id\": \"550e8400-e29b-41d4-a716-446655440000\",\n \"results\": [\n {\n \"changed\": true,\n \"fingerprint\": \"SHA256:a5CeY6Lh3ZXkJOqGyuwb24kQeVjgag1gc9ujzv++nhE\",\n \"hostname\": \"web-01\",\n \"status\": \"ok\"\n }\n ]\n}\n```\n\nA key after a last line with no line break, on one host:\n\n```ansi\n$ osapi client node user sshkey create --target web-01 --name osapitest --key \"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGLPeEZQDbhOrSIx6gISjxXIcREV3rwL517pX6m9G5jc other@example\"\n\x1b[1;38;2;0;213;255mResults:\x1b[0m\n \x1b[38;2;10;143;176mHOSTNAME \x1b[0m\x1b[38;2;10;143;176mSTATUS \x1b[0m\x1b[38;2;10;143;176mFINGERPRINT\x1b[0m\n \x1b[1mweb-01\x1b[0m \x1b[38;2;103;234;147mchanged\x1b[0m SHA256:a5CeY6Lh3ZXkJOqGyuwb24kQeVjgag1gc9ujzv++nhE\n\n 1 host: \x1b[38;2;103;234;147m1 changed\x1b[0m \x1b[38;2;138;138;138mjob 550e8400-e29b-41d4-a716-446655440000\x1b[0m \x1b[38;2;138;138;138mtrace 26e448c9dbe1c4a8d216a98c675079c9\x1b[0m\n```\n\nOn each host, where one cannot run it:\n\n```ansi\n$ osapi client node user sshkey create --target _all --name osapitest --key \"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGLPeEZQDbhOrSIx6gISjxXIcREV3rwL517pX6m9G5jc other@example\"\n\x1b[1;38;2;0;213;255mResults:\x1b[0m\n \x1b[38;2;10;143;176mHOSTNAME \x1b[0m\x1b[38;2;10;143;176mSTATUS \x1b[0m\x1b[38;2;10;143;176mFINGERPRINT\x1b[0m\n \x1b[1mweb-01\x1b[0m \x1b[38;2;103;234;147mchanged\x1b[0m SHA256:a5CeY6Lh3ZXkJOqGyuwb24kQeVjgag1gc9ujzv++nhE\n \x1b[1mweb-02\x1b[0m \x1b[38;2;103;234;147mchanged\x1b[0m SHA256:a5CeY6Lh3ZXkJOqGyuwb24kQeVjgag1gc9ujzv++nhE\n\n 3 hosts: \x1b[38;2;103;234;147m2 changed\x1b[0m, \x1b[38;5;222m1 skipped\x1b[0m \x1b[38;2;138;138;138mjob 550e8400-e29b-41d4-a716-446655440000\x1b[0m \x1b[38;2;138;138;138mtrace 26e448c9dbe1c4a8d216a98c675079c9\x1b[0m\n\n\x1b[1;38;2;255;0;255mDetails:\x1b[0m\n \x1b[1mmac-01\x1b[0m \x1b[38;5;222mskipped\x1b[0m operation not supported on this OS family\n```\n\nWith `--json`, the API's response:\n\n```json\n{\n \"job_id\": \"550e8400-e29b-41d4-a716-446655440000\",\n \"results\": [\n {\n \"changed\": true,\n \"fingerprint\": \"SHA256:a5CeY6Lh3ZXkJOqGyuwb24kQeVjgag1gc9ujzv++nhE\",\n \"hostname\": \"web-01\",\n \"status\": \"ok\"\n }\n ]\n}\n```\n\nA key the user has, on one host:\n\n```ansi\n$ osapi client node user sshkey create --target web-01 --name osapitest --key \"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJl85dcLw7lIdX+IyXEXT00CTCezv/2E1jvolleleo6Z osapitest@example\"\n\x1b[1;38;2;0;213;255mResults:\x1b[0m\n \x1b[38;2;10;143;176mHOSTNAME \x1b[0m\x1b[38;2;10;143;176mSTATUS \x1b[0m\x1b[38;2;10;143;176mFINGERPRINT\x1b[0m\n \x1b[1mweb-01\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk\n\n 1 host: \x1b[38;2;103;234;147m1 ok\x1b[0m \x1b[38;2;138;138;138mjob 550e8400-e29b-41d4-a716-446655440000\x1b[0m \x1b[38;2;138;138;138mtrace 26e448c9dbe1c4a8d216a98c675079c9\x1b[0m\n```\n\nOn each host, where one cannot run it:\n\n```ansi\n$ osapi client node user sshkey create --target _all --name osapitest --key \"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJl85dcLw7lIdX+IyXEXT00CTCezv/2E1jvolleleo6Z osapitest@example\"\n\x1b[1;38;2;0;213;255mResults:\x1b[0m\n \x1b[38;2;10;143;176mHOSTNAME \x1b[0m\x1b[38;2;10;143;176mSTATUS \x1b[0m\x1b[38;2;10;143;176mFINGERPRINT\x1b[0m\n \x1b[1mweb-01\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk\n \x1b[1mweb-02\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk\n\n 3 hosts: \x1b[38;2;103;234;147m2 ok\x1b[0m, \x1b[38;5;222m1 skipped\x1b[0m \x1b[38;2;138;138;138mjob 550e8400-e29b-41d4-a716-446655440000\x1b[0m \x1b[38;2;138;138;138mtrace 26e448c9dbe1c4a8d216a98c675079c9\x1b[0m\n\n\x1b[1;38;2;255;0;255mDetails:\x1b[0m\n \x1b[1mmac-01\x1b[0m \x1b[38;5;222mskipped\x1b[0m operation not supported on this OS family\n```\n\nWith `--json`, the API's response:\n\n```json\n{\n \"job_id\": \"550e8400-e29b-41d4-a716-446655440000\",\n \"results\": [\n {\n \"changed\": false,\n \"fingerprint\": \"SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk\",\n \"hostname\": \"web-01\",\n \"status\": \"ok\"\n }\n ]\n}\n```\n\nWith the default settings, each example does this on the host:\n\n| Example | On the host |\n| --- | --- |\n| Add a key | writes `/home/osapitest/.ssh/authorized_keys`: `ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJl85dcLw7lIdX+IyXEXT00CTCezv/2E1jvolleleo6Z osapitest@example`; runs `chown -R 1001:1001 /home/osapitest/.ssh` |\n| Add a second key | writes `/home/osapitest/.ssh/authorized_keys`: `ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJl85dcLw7lIdX+IyXEXT00CTCezv/2E1jvolleleo6Z osapitest@example\\nssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGLPeEZQDbhOrSIx6gISjxXIcREV3rwL517pX6m9G5jc other@example`; runs `chown -R 1001:1001 /home/osapitest/.ssh` |\n| A key after a last line with no line break | writes `/home/osapitest/.ssh/authorized_keys`: `ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJl85dcLw7lIdX+IyXEXT00CTCezv/2E1jvolleleo6Z osapitest@example\\nssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGLPeEZQDbhOrSIx6gISjxXIcREV3rwL517pX6m9G5jc other@example`; runs `chown -R 1001:1001 /home/osapitest/.ssh` |\n\nThe command fails in these cases:\n\n| Call | Flags | Fails with |\n| --- | --- | --- |\n| A line with no public key | `--name osapitest --key \"not a key\"` | not an SSH public key |\n| A key that is not base64 | `--name osapitest --key \"ssh-ed25519 !!!\"` | not an SSH public key |\n| A user that the host does not have | `--name nobody --key \"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJl85dcLw7lIdX+IyXEXT00CTCezv/2E1jvolleleo6Z osapitest@example\"` | not found |\n| A name that is not a user name | `--name \"Bad;name\" --key \"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJl85dcLw7lIdX+IyXEXT00CTCezv/2E1jvolleleo6Z osapitest@example\"` | Name |\n| A name over 32 characters | `--name aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa --key \"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJl85dcLw7lIdX+IyXEXT00CTCezv/2E1jvolleleo6Z osapitest@example\"` | max |\n| A key with a line break | `--name osapitest --key \"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJl85dcLw7lIdX+IyXEXT00CTCezv/2E1jvolleleo6Z osapitest@example\\nssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGLPeEZQDbhOrSIx6gISjxXIcREV3rwL517pX6m9G5jc other@example\"` | no_linebreak |"). Errors(endpoint.NotFound(behavior.ErrNotFound, "The host does not have what the request names, such as the object of a deploy."), endpoint.Conflict(behavior.ErrNotManaged, "osapi did not deploy the item, so it does not change it, or the host does not have a program that the method needs.").Because(types.ReasonNotManaged), endpoint.Conflict(behavior.ErrNotInstalled, "osapi did not deploy the item, so it does not change it, or the host does not have a program that the method needs.").Because(types.ReasonNotInstalled), endpoint.Invalid(dispatch.ErrInvalid, "The request is not valid, or the host refuses the input, such as a path that is a directory.")), endpoint.Delete[DeleteRequest, UserSshkeyDeleteResponse]("delete"). Handle(HandleDelete). ID("DeleteNodeUserSshkey"). Describe("Remove an authorized SSH key of a user"). Permission("user:write"). Returns("Each target host's result, with whether it changed."). Explain("Removes each line of the key with the fingerprint from ~/.ssh/authorized_keys of the user, and keeps the other lines as they are. A key that the file does not have, a user with no file, or a user that the host does not have, changes nothing. It runs on the Debian family only, and elsewhere reports skipped."). Example("--target web-01 --name osapitest --fingerprint SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk", "Remove a key"). Example("--target web-01 --name osapitest --fingerprint SHA256:a5CeY6Lh3ZXkJOqGyuwb24kQeVjgag1gc9ujzv++nhE", "A key the user does not have"). Example("--target web-01 --name nobody --fingerprint SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk", "A user that the host does not have"). Result("Remove a key, on one host:\n\n```ansi\n$ osapi client node user sshkey delete --target web-01 --name osapitest --fingerprint SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk\n\x1b[1;38;2;0;213;255mResults:\x1b[0m\n \x1b[38;2;10;143;176mHOSTNAME \x1b[0m\x1b[38;2;10;143;176mSTATUS \x1b[0m\x1b[38;2;10;143;176mFINGERPRINT\x1b[0m\n \x1b[1mweb-01\x1b[0m \x1b[38;2;103;234;147mchanged\x1b[0m SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk\n\n 1 host: \x1b[38;2;103;234;147m1 changed\x1b[0m \x1b[38;2;138;138;138mjob 550e8400-e29b-41d4-a716-446655440000\x1b[0m \x1b[38;2;138;138;138mtrace 26e448c9dbe1c4a8d216a98c675079c9\x1b[0m\n```\n\nOn each host, where one cannot run it:\n\n```ansi\n$ osapi client node user sshkey delete --target _all --name osapitest --fingerprint SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk\n\x1b[1;38;2;0;213;255mResults:\x1b[0m\n \x1b[38;2;10;143;176mHOSTNAME \x1b[0m\x1b[38;2;10;143;176mSTATUS \x1b[0m\x1b[38;2;10;143;176mFINGERPRINT\x1b[0m\n \x1b[1mweb-01\x1b[0m \x1b[38;2;103;234;147mchanged\x1b[0m SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk\n \x1b[1mweb-02\x1b[0m \x1b[38;2;103;234;147mchanged\x1b[0m SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk\n\n 3 hosts: \x1b[38;2;103;234;147m2 changed\x1b[0m, \x1b[38;5;222m1 skipped\x1b[0m \x1b[38;2;138;138;138mjob 550e8400-e29b-41d4-a716-446655440000\x1b[0m \x1b[38;2;138;138;138mtrace 26e448c9dbe1c4a8d216a98c675079c9\x1b[0m\n\n\x1b[1;38;2;255;0;255mDetails:\x1b[0m\n \x1b[1mmac-01\x1b[0m \x1b[38;5;222mskipped\x1b[0m operation not supported on this OS family\n```\n\nWith `--json`, the API's response:\n\n```json\n{\n \"job_id\": \"550e8400-e29b-41d4-a716-446655440000\",\n \"results\": [\n {\n \"changed\": true,\n \"fingerprint\": \"SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk\",\n \"hostname\": \"web-01\",\n \"status\": \"ok\"\n }\n ]\n}\n```\n\nA key the user does not have, on one host:\n\n```ansi\n$ osapi client node user sshkey delete --target web-01 --name osapitest --fingerprint SHA256:a5CeY6Lh3ZXkJOqGyuwb24kQeVjgag1gc9ujzv++nhE\n\x1b[1;38;2;0;213;255mResults:\x1b[0m\n \x1b[38;2;10;143;176mHOSTNAME \x1b[0m\x1b[38;2;10;143;176mSTATUS \x1b[0m\x1b[38;2;10;143;176mFINGERPRINT\x1b[0m\n \x1b[1mweb-01\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m SHA256:a5CeY6Lh3ZXkJOqGyuwb24kQeVjgag1gc9ujzv++nhE\n\n 1 host: \x1b[38;2;103;234;147m1 ok\x1b[0m \x1b[38;2;138;138;138mjob 550e8400-e29b-41d4-a716-446655440000\x1b[0m \x1b[38;2;138;138;138mtrace 26e448c9dbe1c4a8d216a98c675079c9\x1b[0m\n```\n\nOn each host, where one cannot run it:\n\n```ansi\n$ osapi client node user sshkey delete --target _all --name osapitest --fingerprint SHA256:a5CeY6Lh3ZXkJOqGyuwb24kQeVjgag1gc9ujzv++nhE\n\x1b[1;38;2;0;213;255mResults:\x1b[0m\n \x1b[38;2;10;143;176mHOSTNAME \x1b[0m\x1b[38;2;10;143;176mSTATUS \x1b[0m\x1b[38;2;10;143;176mFINGERPRINT\x1b[0m\n \x1b[1mweb-01\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m SHA256:a5CeY6Lh3ZXkJOqGyuwb24kQeVjgag1gc9ujzv++nhE\n \x1b[1mweb-02\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m SHA256:a5CeY6Lh3ZXkJOqGyuwb24kQeVjgag1gc9ujzv++nhE\n\n 3 hosts: \x1b[38;2;103;234;147m2 ok\x1b[0m, \x1b[38;5;222m1 skipped\x1b[0m \x1b[38;2;138;138;138mjob 550e8400-e29b-41d4-a716-446655440000\x1b[0m \x1b[38;2;138;138;138mtrace 26e448c9dbe1c4a8d216a98c675079c9\x1b[0m\n\n\x1b[1;38;2;255;0;255mDetails:\x1b[0m\n \x1b[1mmac-01\x1b[0m \x1b[38;5;222mskipped\x1b[0m operation not supported on this OS family\n```\n\nWith `--json`, the API's response:\n\n```json\n{\n \"job_id\": \"550e8400-e29b-41d4-a716-446655440000\",\n \"results\": [\n {\n \"changed\": false,\n \"fingerprint\": \"SHA256:a5CeY6Lh3ZXkJOqGyuwb24kQeVjgag1gc9ujzv++nhE\",\n \"hostname\": \"web-01\",\n \"status\": \"ok\"\n }\n ]\n}\n```\n\nA user that the host does not have, on one host:\n\n```ansi\n$ osapi client node user sshkey delete --target web-01 --name nobody --fingerprint SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk\n\x1b[1;38;2;0;213;255mResults:\x1b[0m\n \x1b[38;2;10;143;176mHOSTNAME \x1b[0m\x1b[38;2;10;143;176mSTATUS \x1b[0m\x1b[38;2;10;143;176mFINGERPRINT\x1b[0m\n \x1b[1mweb-01\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk\n\n 1 host: \x1b[38;2;103;234;147m1 ok\x1b[0m \x1b[38;2;138;138;138mjob 550e8400-e29b-41d4-a716-446655440000\x1b[0m \x1b[38;2;138;138;138mtrace 26e448c9dbe1c4a8d216a98c675079c9\x1b[0m\n```\n\nOn each host, where one cannot run it:\n\n```ansi\n$ osapi client node user sshkey delete --target _all --name nobody --fingerprint SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk\n\x1b[1;38;2;0;213;255mResults:\x1b[0m\n \x1b[38;2;10;143;176mHOSTNAME \x1b[0m\x1b[38;2;10;143;176mSTATUS \x1b[0m\x1b[38;2;10;143;176mFINGERPRINT\x1b[0m\n \x1b[1mweb-01\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk\n \x1b[1mweb-02\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk\n\n 3 hosts: \x1b[38;2;103;234;147m2 ok\x1b[0m, \x1b[38;5;222m1 skipped\x1b[0m \x1b[38;2;138;138;138mjob 550e8400-e29b-41d4-a716-446655440000\x1b[0m \x1b[38;2;138;138;138mtrace 26e448c9dbe1c4a8d216a98c675079c9\x1b[0m\n\n\x1b[1;38;2;255;0;255mDetails:\x1b[0m\n \x1b[1mmac-01\x1b[0m \x1b[38;5;222mskipped\x1b[0m operation not supported on this OS family\n```\n\nWith `--json`, the API's response:\n\n```json\n{\n \"job_id\": \"550e8400-e29b-41d4-a716-446655440000\",\n \"results\": [\n {\n \"changed\": false,\n \"fingerprint\": \"SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk\",\n \"hostname\": \"web-01\",\n \"status\": \"ok\"\n }\n ]\n}\n```\n\nWith the default settings, each example does this on the host:\n\n| Example | On the host |\n| --- | --- |\n| Remove a key | writes `/home/osapitest/.ssh/authorized_keys`: `ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGLPeEZQDbhOrSIx6gISjxXIcREV3rwL517pX6m9G5jc other@example` |\n\nThe command fails in these cases:\n\n| Call | Flags | Fails with |\n| --- | --- | --- |\n| A fingerprint that is not SHA256 | `--name osapitest --fingerprint MD5:aa` | Fingerprint |\n| A fingerprint with a line break | `--name osapitest --fingerprint \"SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk\\nSHA256:a5CeY6Lh3ZXkJOqGyuwb24kQeVjgag1gc9ujzv++nhE\"` | no_linebreak |\n| A name that is not a user name | `--name \"Bad;name\" --fingerprint SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk` | Name |\n| A name over 32 characters | `--name aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa --fingerprint SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk` | max |"). Errors(endpoint.NotFound(behavior.ErrNotFound, "The host does not have what the request names, such as the object of a deploy."), endpoint.Conflict(behavior.ErrNotManaged, "osapi did not deploy the item, so it does not change it, or the host does not have a program that the method needs.").Because(types.ReasonNotManaged), endpoint.Conflict(behavior.ErrNotInstalled, "osapi did not deploy the item, so it does not change it, or the host does not have a program that the method needs.").Because(types.ReasonNotInstalled), endpoint.Invalid(dispatch.ErrInvalid, "The request is not valid, or the host refuses the input, such as a path that is a directory.")), )
Group is sshkey as an endpoint group, which its spec comes from.
Functions ¶
Types ¶
type CreateRequest ¶
type CreateRequest struct {
Hostname string `` /* 182-byte string literal not displayed */
Name string `doc:"The user, such as alice" in:"path" json:"name" param:"UserSshkeyName" validate:"required,max=32,account_name"`
Body UserSshkeyCreateRequest `in:"body" validate:"required"`
}
CreateRequest is the request of sshkey create: its target and its input.
type DeleteRequest ¶
type DeleteRequest struct {
Hostname string `` /* 182-byte string literal not displayed */
Name string `doc:"The user, such as alice" in:"path" json:"name" param:"UserSshkeyName" validate:"required,max=32,account_name"`
Body UserSshkeyDeleteRequest `in:"body" validate:"required"`
}
DeleteRequest is the request of sshkey delete: its target and its input.
type ListRequest ¶
type ListRequest struct {
Hostname string `` /* 182-byte string literal not displayed */
Name string `doc:"The user, such as alice" in:"path" json:"name" param:"UserSshkeyName" validate:"required,max=32,account_name"`
}
ListRequest is the request of sshkey list: its target and its input.
type UserSshkeyCollectionResponse ¶
type UserSshkeyCollectionResponse struct {
JobID string `` /* 133-byte string literal not displayed */
Results []UserSshkeyKey `json:"results"`
}
UserSshkeyCollectionResponse is each target host's result.
func HandleList ¶
func HandleList( ctx context.Context, d dispatch.Deps, in ListRequest, ) (UserSshkeyCollectionResponse, error)
HandleList runs sshkey list on the target, for the endpoint server.
type UserSshkeyCreateRequest ¶
type UserSshkeyCreateRequest struct {
Key string `` /* 142-byte string literal not displayed */
}
UserSshkeyCreateRequest is the body of sshkey create.
type UserSshkeyCreateResponse ¶
type UserSshkeyCreateResponse struct {
JobID string `` /* 133-byte string literal not displayed */
Results []UserSshkeyResult `json:"results"`
}
UserSshkeyCreateResponse is each target host's result.
func HandleCreate ¶
func HandleCreate( ctx context.Context, d dispatch.Deps, in CreateRequest, ) (UserSshkeyCreateResponse, error)
HandleCreate runs sshkey create on the target, for the endpoint server.
type UserSshkeyDeleteRequest ¶
type UserSshkeyDeleteRequest struct {
Fingerprint string `` /* 128-byte string literal not displayed */
}
UserSshkeyDeleteRequest is the body of sshkey delete.
type UserSshkeyDeleteResponse ¶
type UserSshkeyDeleteResponse struct {
JobID string `` /* 133-byte string literal not displayed */
Results []UserSshkeyResult `json:"results"`
}
UserSshkeyDeleteResponse is each target host's result.
func HandleDelete ¶
func HandleDelete( ctx context.Context, d dispatch.Deps, in DeleteRequest, ) (UserSshkeyDeleteResponse, error)
HandleDelete runs sshkey delete on the target, for the endpoint server.
type UserSshkeyKey ¶
type UserSshkeyKey struct {
Hostname string `doc:"Hostname of the agent that produced this result." json:"hostname"`
Status types.RowStatus `doc:"The status of the operation for this host." json:"status"`
Type *string `doc:"The key type, such as ssh-ed25519" json:"type,omitempty"`
Fingerprint *string `doc:"The SHA256 fingerprint of the key" json:"fingerprint,omitempty"`
Comment *string `doc:"The comment after the key, such as alice@laptop" json:"comment,omitempty"`
Options *string `doc:"The options before the key, such as from=\"10.0.0.0/8\"" json:"options,omitempty"`
Error *string `doc:"Error message if the agent failed." json:"error,omitempty"`
}
UserSshkeyKey is the result of sshkey on one host.
type UserSshkeyResult ¶
type UserSshkeyResult struct {
Hostname string `doc:"Hostname of the agent that produced this result." json:"hostname"`
Status types.RowStatus `doc:"The status of the operation for this host." json:"status"`
Fingerprint *string `doc:"The SHA256 fingerprint of the key" json:"fingerprint,omitempty"`
Changed *bool `doc:"Whether the host changed" json:"changed,omitempty"`
Error *string `doc:"Error message if the agent failed." json:"error,omitempty"`
}
UserSshkeyResult is the result of sshkey on one host.