knuckles-cli 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- knuckles_cli/__init__.py +3 -0
- knuckles_cli/__main__.py +7 -0
- knuckles_cli/api.py +252 -0
- knuckles_cli/cli.py +684 -0
- knuckles_cli/config.py +201 -0
- knuckles_cli/doctor.py +250 -0
- knuckles_cli/envfile.py +103 -0
- knuckles_cli/errors.py +43 -0
- knuckles_cli/ops.py +451 -0
- knuckles_cli/providers.py +365 -0
- knuckles_cli/py.typed +0 -0
- knuckles_cli-0.2.0.dist-info/METADATA +140 -0
- knuckles_cli-0.2.0.dist-info/RECORD +17 -0
- knuckles_cli-0.2.0.dist-info/WHEEL +5 -0
- knuckles_cli-0.2.0.dist-info/entry_points.txt +2 -0
- knuckles_cli-0.2.0.dist-info/licenses/LICENSE +21 -0
- knuckles_cli-0.2.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
"""Local parsing and validation of sign-in provider credentials.
|
|
2
|
+
|
|
3
|
+
Everything here runs before anything is uploaded, so a wrong file or a
|
|
4
|
+
typo fails on the operator's machine with a specific message instead of
|
|
5
|
+
as an opaque provider error at a user's first sign-in.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import json
|
|
11
|
+
import re
|
|
12
|
+
from dataclasses import dataclass, field
|
|
13
|
+
from email.utils import parseaddr
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
from urllib.parse import urlsplit
|
|
16
|
+
|
|
17
|
+
import requests
|
|
18
|
+
from cryptography.hazmat.primitives.asymmetric import ec
|
|
19
|
+
from cryptography.hazmat.primitives.serialization import load_pem_private_key
|
|
20
|
+
|
|
21
|
+
from knuckles_cli.errors import INVALID_INPUT, CliError
|
|
22
|
+
|
|
23
|
+
RESEND_DOMAINS_URL = "https://api.resend.com/domains"
|
|
24
|
+
|
|
25
|
+
_APPLE_ID_RE = re.compile(r"^[A-Z0-9]{10}$")
|
|
26
|
+
_APPLE_KEY_FILENAME_RE = re.compile(r"^AuthKey_([A-Z0-9]{10})\.p8$")
|
|
27
|
+
_SERVICES_ID_RE = re.compile(r"^[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)+$")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def is_local_host(host: str) -> bool:
|
|
31
|
+
"""Whether a hostname is a local-development host.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
host: Bare hostname, no port.
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
``True`` for localhost, loopback addresses, and ``*.localhost``.
|
|
38
|
+
"""
|
|
39
|
+
return host in ("localhost", "127.0.0.1", "::1") or host.endswith(".localhost")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def origin_of(url: str) -> str:
|
|
43
|
+
"""Reduce a URL to its ``scheme://host[:port]`` origin.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
url: Any absolute URL.
|
|
47
|
+
|
|
48
|
+
Returns:
|
|
49
|
+
The lowercase origin.
|
|
50
|
+
|
|
51
|
+
Raises:
|
|
52
|
+
CliError: If the URL is not absolute http(s).
|
|
53
|
+
"""
|
|
54
|
+
parts = urlsplit(url.strip())
|
|
55
|
+
if parts.scheme not in ("http", "https") or not parts.netloc:
|
|
56
|
+
raise CliError(INVALID_INPUT, f"Not an http(s) URL: {url!r}")
|
|
57
|
+
return f"{parts.scheme}://{parts.netloc}".lower()
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@dataclass(frozen=True)
|
|
61
|
+
class GoogleCredentials:
|
|
62
|
+
"""The useful parts of Google's ``client_secret_*.json``.
|
|
63
|
+
|
|
64
|
+
Attributes:
|
|
65
|
+
client_id: OAuth client id.
|
|
66
|
+
client_secret: OAuth client secret.
|
|
67
|
+
redirect_uris: Authorized redirect URIs from the console.
|
|
68
|
+
"""
|
|
69
|
+
|
|
70
|
+
client_id: str
|
|
71
|
+
client_secret: str
|
|
72
|
+
redirect_uris: list[str] = field(default_factory=list)
|
|
73
|
+
|
|
74
|
+
@property
|
|
75
|
+
def redirect_origins(self) -> list[str]:
|
|
76
|
+
"""Distinct origins of the authorized redirect URIs.
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
Origins in first-seen order.
|
|
80
|
+
"""
|
|
81
|
+
origins: list[str] = []
|
|
82
|
+
for uri in self.redirect_uris:
|
|
83
|
+
origin = origin_of(uri)
|
|
84
|
+
if origin not in origins:
|
|
85
|
+
origins.append(origin)
|
|
86
|
+
return origins
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def parse_google_client_secret(text: str) -> GoogleCredentials:
|
|
90
|
+
"""Parse the JSON file Google Cloud Console downloads for a client.
|
|
91
|
+
|
|
92
|
+
Args:
|
|
93
|
+
text: File contents.
|
|
94
|
+
|
|
95
|
+
Returns:
|
|
96
|
+
The parsed credentials.
|
|
97
|
+
|
|
98
|
+
Raises:
|
|
99
|
+
CliError: If the file is not JSON, is not a "Web application"
|
|
100
|
+
client, or lacks the id or secret.
|
|
101
|
+
"""
|
|
102
|
+
try:
|
|
103
|
+
raw = json.loads(text)
|
|
104
|
+
except json.JSONDecodeError as exc:
|
|
105
|
+
raise CliError(INVALID_INPUT, f"Google client file is not JSON: {exc}") from exc
|
|
106
|
+
web = raw.get("web") if isinstance(raw, dict) else None
|
|
107
|
+
if not isinstance(web, dict):
|
|
108
|
+
raise CliError(
|
|
109
|
+
INVALID_INPUT,
|
|
110
|
+
"Google client file has no 'web' block. Create the OAuth client "
|
|
111
|
+
"with application type 'Web application' and download it again.",
|
|
112
|
+
)
|
|
113
|
+
client_id = web.get("client_id")
|
|
114
|
+
client_secret = web.get("client_secret")
|
|
115
|
+
if not isinstance(client_id, str) or not isinstance(client_secret, str):
|
|
116
|
+
raise CliError(
|
|
117
|
+
INVALID_INPUT, "Google client file is missing client_id or client_secret."
|
|
118
|
+
)
|
|
119
|
+
uris = web.get("redirect_uris") or []
|
|
120
|
+
return GoogleCredentials(
|
|
121
|
+
client_id=client_id,
|
|
122
|
+
client_secret=client_secret,
|
|
123
|
+
redirect_uris=[u for u in uris if isinstance(u, str)],
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def validate_apple_private_key(pem: str) -> None:
|
|
128
|
+
"""Check that a ``.p8`` file is the P-256 key Apple issues.
|
|
129
|
+
|
|
130
|
+
Args:
|
|
131
|
+
pem: PEM text of the key.
|
|
132
|
+
|
|
133
|
+
Raises:
|
|
134
|
+
CliError: If the text is not a PEM private key or is not on
|
|
135
|
+
the P-256 curve (Apple's client secret is ES256).
|
|
136
|
+
"""
|
|
137
|
+
try:
|
|
138
|
+
key = load_pem_private_key(pem.encode(), password=None)
|
|
139
|
+
except (ValueError, TypeError) as exc:
|
|
140
|
+
raise CliError(INVALID_INPUT, f"Not a PEM private key: {exc}") from exc
|
|
141
|
+
if not isinstance(key, ec.EllipticCurvePrivateKey) or not isinstance(
|
|
142
|
+
key.curve, ec.SECP256R1
|
|
143
|
+
):
|
|
144
|
+
raise CliError(
|
|
145
|
+
INVALID_INPUT,
|
|
146
|
+
"Apple Sign-in keys are P-256 EC keys. Download the .p8 from "
|
|
147
|
+
"Certificates, Identifiers & Profiles > Keys.",
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def apple_key_id_from_filename(path: str) -> str | None:
|
|
152
|
+
"""Read the key id out of Apple's ``AuthKey_<KEYID>.p8`` filename.
|
|
153
|
+
|
|
154
|
+
Args:
|
|
155
|
+
path: Path to the key file.
|
|
156
|
+
|
|
157
|
+
Returns:
|
|
158
|
+
The ten-character key id, or ``None`` if the file was renamed.
|
|
159
|
+
"""
|
|
160
|
+
match = _APPLE_KEY_FILENAME_RE.match(Path(path).name)
|
|
161
|
+
return match.group(1) if match else None
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def validate_apple_identifier(value: str, name: str) -> str:
|
|
165
|
+
"""Normalize and check an Apple team id or key id.
|
|
166
|
+
|
|
167
|
+
Args:
|
|
168
|
+
value: The id as typed.
|
|
169
|
+
name: Field name for the error message.
|
|
170
|
+
|
|
171
|
+
Returns:
|
|
172
|
+
The uppercase id.
|
|
173
|
+
|
|
174
|
+
Raises:
|
|
175
|
+
CliError: If it is not ten alphanumerics.
|
|
176
|
+
"""
|
|
177
|
+
normalized = value.strip().upper()
|
|
178
|
+
if not _APPLE_ID_RE.match(normalized):
|
|
179
|
+
raise CliError(
|
|
180
|
+
INVALID_INPUT, f"{name} must be 10 letters/digits, got {value!r}."
|
|
181
|
+
)
|
|
182
|
+
return normalized
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def validate_services_id(value: str) -> str:
|
|
186
|
+
"""Check an Apple Services ID looks like reverse-DNS.
|
|
187
|
+
|
|
188
|
+
Args:
|
|
189
|
+
value: The Services ID as typed.
|
|
190
|
+
|
|
191
|
+
Returns:
|
|
192
|
+
The trimmed Services ID.
|
|
193
|
+
|
|
194
|
+
Raises:
|
|
195
|
+
CliError: If it is not dotted reverse-DNS.
|
|
196
|
+
"""
|
|
197
|
+
trimmed = value.strip()
|
|
198
|
+
if not _SERVICES_ID_RE.match(trimmed):
|
|
199
|
+
raise CliError(
|
|
200
|
+
INVALID_INPUT,
|
|
201
|
+
f"Apple Services ID should look like com.example.web, got {value!r}.",
|
|
202
|
+
)
|
|
203
|
+
return trimmed
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def passkey_config(
|
|
207
|
+
*, origin: str, rp_name: str, rp_id: str | None = None
|
|
208
|
+
) -> dict[str, str]:
|
|
209
|
+
"""Derive the WebAuthn relying-party columns for a tenant.
|
|
210
|
+
|
|
211
|
+
Args:
|
|
212
|
+
origin: The site origin passkeys are used from.
|
|
213
|
+
rp_name: Name shown in the browser's passkey prompt.
|
|
214
|
+
rp_id: Optional relying-party id; defaults to the origin host.
|
|
215
|
+
|
|
216
|
+
Returns:
|
|
217
|
+
``webauthn_origin`` / ``webauthn_rp_id`` / ``webauthn_rp_name``.
|
|
218
|
+
|
|
219
|
+
Raises:
|
|
220
|
+
CliError: If the origin is not a secure context or the rp_id
|
|
221
|
+
is not the origin host or one of its parent domains.
|
|
222
|
+
"""
|
|
223
|
+
normalized = origin_of(origin)
|
|
224
|
+
parts = urlsplit(normalized)
|
|
225
|
+
host = parts.hostname or ""
|
|
226
|
+
if parts.scheme != "https" and not is_local_host(host):
|
|
227
|
+
raise CliError(
|
|
228
|
+
INVALID_INPUT,
|
|
229
|
+
f"Passkeys need https (or localhost); {normalized} is not secure.",
|
|
230
|
+
)
|
|
231
|
+
effective_rp_id = (rp_id or host).strip().lower()
|
|
232
|
+
if host != effective_rp_id and not host.endswith(f".{effective_rp_id}"):
|
|
233
|
+
raise CliError(
|
|
234
|
+
INVALID_INPUT,
|
|
235
|
+
f"rp_id {effective_rp_id!r} must be {host!r} or a parent domain of it.",
|
|
236
|
+
)
|
|
237
|
+
return {
|
|
238
|
+
"webauthn_origin": normalized,
|
|
239
|
+
"webauthn_rp_id": effective_rp_id,
|
|
240
|
+
"webauthn_rp_name": rp_name,
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def email_address_of(from_value: str) -> str:
|
|
245
|
+
"""Extract the bare address from a From value.
|
|
246
|
+
|
|
247
|
+
Args:
|
|
248
|
+
from_value: ``addr`` or ``Name <addr>``.
|
|
249
|
+
|
|
250
|
+
Returns:
|
|
251
|
+
The address.
|
|
252
|
+
|
|
253
|
+
Raises:
|
|
254
|
+
CliError: If no address is present.
|
|
255
|
+
"""
|
|
256
|
+
_, address = parseaddr(from_value)
|
|
257
|
+
if "@" not in address:
|
|
258
|
+
raise CliError(INVALID_INPUT, f"No email address in {from_value!r}.")
|
|
259
|
+
return address
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
def check_resend_domain(
|
|
263
|
+
api_key: str, domain: str, *, timeout: float = 10.0
|
|
264
|
+
) -> tuple[str, str]:
|
|
265
|
+
"""Ask Resend whether a sending domain is verified for this key.
|
|
266
|
+
|
|
267
|
+
Args:
|
|
268
|
+
api_key: Resend API key.
|
|
269
|
+
domain: The From address's domain.
|
|
270
|
+
timeout: Request timeout in seconds.
|
|
271
|
+
|
|
272
|
+
Returns:
|
|
273
|
+
Tuple of status (``ok`` / ``warn`` / ``fail``) and detail.
|
|
274
|
+
"""
|
|
275
|
+
try:
|
|
276
|
+
response = requests.get(
|
|
277
|
+
RESEND_DOMAINS_URL,
|
|
278
|
+
headers={"Authorization": f"Bearer {api_key}"},
|
|
279
|
+
timeout=timeout,
|
|
280
|
+
)
|
|
281
|
+
except requests.RequestException as exc:
|
|
282
|
+
return "warn", f"Could not reach Resend to check {domain}: {exc}"
|
|
283
|
+
try:
|
|
284
|
+
body = response.json()
|
|
285
|
+
except ValueError:
|
|
286
|
+
body = {}
|
|
287
|
+
if not response.ok:
|
|
288
|
+
name = str(body.get("name", "")) if isinstance(body, dict) else ""
|
|
289
|
+
if name == "restricted_api_key":
|
|
290
|
+
return "warn", (
|
|
291
|
+
"This is a sending-only Resend key, so the domain could not be "
|
|
292
|
+
f"checked. Confirm {domain} shows Verified at resend.com/domains."
|
|
293
|
+
)
|
|
294
|
+
message = body.get("message", "") if isinstance(body, dict) else ""
|
|
295
|
+
return (
|
|
296
|
+
"fail",
|
|
297
|
+
f"Resend rejected the API key ({response.status_code}): {message}",
|
|
298
|
+
)
|
|
299
|
+
domains = body.get("data", []) if isinstance(body, dict) else []
|
|
300
|
+
for entry in domains:
|
|
301
|
+
if isinstance(entry, dict) and entry.get("name") == domain:
|
|
302
|
+
status = entry.get("status")
|
|
303
|
+
if status == "verified":
|
|
304
|
+
return "ok", f"{domain} is verified in Resend."
|
|
305
|
+
return "fail", (
|
|
306
|
+
f"{domain} is {status} in Resend; add its DNS records and wait "
|
|
307
|
+
"for verification."
|
|
308
|
+
)
|
|
309
|
+
return "fail", f"{domain} has not been added to this Resend account."
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
@dataclass(frozen=True)
|
|
313
|
+
class ConfigGroup:
|
|
314
|
+
"""One tenant-config group on ``app_clients`` (Decision #020).
|
|
315
|
+
|
|
316
|
+
Attributes:
|
|
317
|
+
name: CLI-facing group name.
|
|
318
|
+
columns: Column names in the group.
|
|
319
|
+
secret_columns: Columns the admin API exposes only as
|
|
320
|
+
``<column>_configured`` booleans.
|
|
321
|
+
atomic: Whether a half-set group fails at sign-in time with
|
|
322
|
+
``TENANT_CONFIG_INCOMPLETE`` (non-atomic fields inherit the
|
|
323
|
+
operator env var individually).
|
|
324
|
+
"""
|
|
325
|
+
|
|
326
|
+
name: str
|
|
327
|
+
columns: tuple[str, ...]
|
|
328
|
+
secret_columns: frozenset[str]
|
|
329
|
+
atomic: bool
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
CONFIG_GROUPS: dict[str, ConfigGroup] = {
|
|
333
|
+
group.name: group
|
|
334
|
+
for group in (
|
|
335
|
+
ConfigGroup(
|
|
336
|
+
"email",
|
|
337
|
+
("resend_api_key", "resend_from_email"),
|
|
338
|
+
frozenset({"resend_api_key"}),
|
|
339
|
+
atomic=False,
|
|
340
|
+
),
|
|
341
|
+
ConfigGroup(
|
|
342
|
+
"google",
|
|
343
|
+
("google_oauth_client_id", "google_oauth_client_secret"),
|
|
344
|
+
frozenset({"google_oauth_client_secret"}),
|
|
345
|
+
atomic=True,
|
|
346
|
+
),
|
|
347
|
+
ConfigGroup(
|
|
348
|
+
"apple",
|
|
349
|
+
(
|
|
350
|
+
"apple_oauth_client_id",
|
|
351
|
+
"apple_oauth_team_id",
|
|
352
|
+
"apple_oauth_key_id",
|
|
353
|
+
"apple_oauth_private_key",
|
|
354
|
+
),
|
|
355
|
+
frozenset({"apple_oauth_private_key"}),
|
|
356
|
+
atomic=True,
|
|
357
|
+
),
|
|
358
|
+
ConfigGroup(
|
|
359
|
+
"passkey",
|
|
360
|
+
("webauthn_rp_id", "webauthn_rp_name", "webauthn_origin"),
|
|
361
|
+
frozenset(),
|
|
362
|
+
atomic=True,
|
|
363
|
+
),
|
|
364
|
+
)
|
|
365
|
+
}
|
knuckles_cli/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: knuckles-cli
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Operator CLI for the Knuckles identity service
|
|
5
|
+
Author-email: Garrett Sooter <garrett.sooter@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/gsooter/knuckles
|
|
8
|
+
Project-URL: Documentation, https://gsooter.github.io/knuckles/cli
|
|
9
|
+
Project-URL: Source, https://github.com/gsooter/knuckles/tree/main/packages/knuckles-cli
|
|
10
|
+
Project-URL: Issues, https://github.com/gsooter/knuckles/issues
|
|
11
|
+
Keywords: authentication,identity,cli,knuckles,oauth,passkey
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Security
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
Requires-Python: >=3.11
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: requests<3,>=2.31
|
|
27
|
+
Requires-Dist: cryptography<46,>=42.0
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: pytest<9,>=8.0; extra == "dev"
|
|
30
|
+
Requires-Dist: pytest-cov<6,>=5.0; extra == "dev"
|
|
31
|
+
Requires-Dist: responses<1,>=0.25; extra == "dev"
|
|
32
|
+
Requires-Dist: mypy<2,>=1.9; extra == "dev"
|
|
33
|
+
Requires-Dist: ruff==0.15.11; extra == "dev"
|
|
34
|
+
Requires-Dist: black<25,>=24.0; extra == "dev"
|
|
35
|
+
Requires-Dist: types-requests<3,>=2.31; extra == "dev"
|
|
36
|
+
Dynamic: license-file
|
|
37
|
+
|
|
38
|
+
# knuckles-cli
|
|
39
|
+
|
|
40
|
+
The operator CLI for [Knuckles](https://github.com/gsooter/knuckles).
|
|
41
|
+
It lets you add a new site, configure its sign-in methods, and check
|
|
42
|
+
that everything is wired correctly, using just your Knuckles URL and
|
|
43
|
+
admin token. You don't need a checkout, database access, or `curl`.
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install knuckles-cli
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
It talks to a running Knuckles over HTTP only: the public discovery
|
|
50
|
+
endpoints plus the `/v1/admin/*` API, so the server needs
|
|
51
|
+
`KNUCKLES_ADMIN_TOKEN` set (Decisions #021 and #025).
|
|
52
|
+
|
|
53
|
+
## Five-minute setup for a new site
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
# 1. Point the CLI at your server. The token is read from
|
|
57
|
+
# $KNUCKLES_ADMIN_TOKEN, a file (--token-file, '-' = stdin), or a
|
|
58
|
+
# hidden prompt. It never goes on the command line.
|
|
59
|
+
knuckles login --url https://auth.example.com
|
|
60
|
+
|
|
61
|
+
# 2. Create the tenant and drop its credentials into the app's .env
|
|
62
|
+
knuckles init my-site --name "My Site" \
|
|
63
|
+
--origin https://my-site.com --origin http://localhost:3000 \
|
|
64
|
+
--env-file ../my-site/.env
|
|
65
|
+
|
|
66
|
+
# 3. Turn on sign-in methods (any subset)
|
|
67
|
+
knuckles providers email my-site --from "My Site <signin@mail.my-site.com>"
|
|
68
|
+
knuckles providers google my-site --client-secret-json ~/Downloads/client_secret_*.json
|
|
69
|
+
knuckles providers apple my-site --services-id com.my-site.web \
|
|
70
|
+
--team-id AB12CD34EF --p8 ~/Downloads/AuthKey_ABCDE12345.p8
|
|
71
|
+
knuckles providers passkey my-site --origin https://my-site.com
|
|
72
|
+
|
|
73
|
+
# 4. Check it
|
|
74
|
+
knuckles doctor my-site
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Commands
|
|
78
|
+
|
|
79
|
+
| Command | What it does |
|
|
80
|
+
|---|---|
|
|
81
|
+
| `login --url URL` | Verifies the admin token against the server, then stores the profile. |
|
|
82
|
+
| `logout` | Forgets the stored profile. |
|
|
83
|
+
| `init ID --name N --origin O [--env-file F]` | Creates a tenant and prints the next setup steps. |
|
|
84
|
+
| `apps list` / `apps show ID` | Lists tenants, or shows one. Secrets appear only as `*_configured` booleans. |
|
|
85
|
+
| `apps create ID --name N --origin O [--env-file F]` | Creates a tenant without the next-steps output. |
|
|
86
|
+
| `apps rotate-secret ID [--env-file F --force]` | Mints a new client secret. The old one stops working immediately. |
|
|
87
|
+
| `apps set-origins ID ORIGIN...` | Replaces the tenant's allowed origins. |
|
|
88
|
+
| `providers google ID --client-secret-json F` | Configures Google from the JSON file Google Cloud Console downloads. It warns if a redirect URI's origin isn't allowed. |
|
|
89
|
+
| `providers apple ID --services-id S --team-id T --p8 F` | Checks the key is P-256 and reads the key id from `AuthKey_<KEYID>.p8`. |
|
|
90
|
+
| `providers email ID --from ADDR` | Configures Resend. It checks that the sending domain is verified before storing the key. |
|
|
91
|
+
| `providers passkey ID --origin O [--rp-id R]` | Derives the WebAuthn relying party and checks that the origin fits under the `rp_id`. |
|
|
92
|
+
| `providers clear ID GROUP` | Resets `email`, `google`, `apple` or `passkey` to the operator env fallback. |
|
|
93
|
+
| `doctor [ID]` | Checks the server (health, `issuer`, JWKS, HTTPS) and each tenant (origins, config groups, passkey fit). |
|
|
94
|
+
|
|
95
|
+
### Where secrets come from
|
|
96
|
+
|
|
97
|
+
The CLI never takes a secret as a command-line argument, because
|
|
98
|
+
those end up in shell history and `ps`. Each secret is read from the
|
|
99
|
+
first source available:
|
|
100
|
+
|
|
101
|
+
| Secret | `--*-file` option (`-` = stdin) | Env var | Otherwise |
|
|
102
|
+
|---|---|---|---|
|
|
103
|
+
| Admin token | `login --token-file` | `KNUCKLES_ADMIN_TOKEN` | hidden prompt |
|
|
104
|
+
| Resend API key | `--api-key-file` | `KNUCKLES_RESEND_API_KEY` | hidden prompt |
|
|
105
|
+
| Google client secret (manual entry) | `--client-secret-file` | `KNUCKLES_GOOGLE_CLIENT_SECRET` | hidden prompt |
|
|
106
|
+
|
|
107
|
+
## For scripts and coding agents
|
|
108
|
+
|
|
109
|
+
- Pass `--json` (before the subcommand) to get the Knuckles API
|
|
110
|
+
envelope: `{"data": ...}` on success, `{"error": {"code", "message"}}`
|
|
111
|
+
on failure. Server error codes such as `APP_CLIENT_NOT_FOUND` are
|
|
112
|
+
passed through verbatim.
|
|
113
|
+
- Exit codes: `0` success, `1` failure (including any failing
|
|
114
|
+
`doctor` check), `2` usage error.
|
|
115
|
+
- No config file needed: `KNUCKLES_URL` and `KNUCKLES_ADMIN_TOKEN`
|
|
116
|
+
override the stored profile.
|
|
117
|
+
- Profiles are stored in `$XDG_CONFIG_HOME/knuckles/config.json`
|
|
118
|
+
(mode 0600), or at `KNUCKLES_CONFIG` if that's set. Select one with
|
|
119
|
+
`--profile NAME` or `KNUCKLES_PROFILE`.
|
|
120
|
+
|
|
121
|
+
## What `doctor` can't see
|
|
122
|
+
|
|
123
|
+
`doctor` sees only what the admin API returns. Encrypted values show
|
|
124
|
+
up as booleans, and whether an empty group inherits the operator's
|
|
125
|
+
env vars depends on server-side state
|
|
126
|
+
(`KNUCKLES_ALLOW_ENV_TENANT_FALLBACK`). That's why empty groups are
|
|
127
|
+
warnings, not failures. Resend domain verification is checked once,
|
|
128
|
+
by `providers email`, while the key is in hand.
|
|
129
|
+
|
|
130
|
+
## Releasing
|
|
131
|
+
|
|
132
|
+
Bump the version in `pyproject.toml` and `__init__.py`, add a
|
|
133
|
+
CHANGELOG entry, merge, then push a tag:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
git tag knuckles-cli-vX.Y.Z && git push origin knuckles-cli-vX.Y.Z
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
`.github/workflows/release-cli.yml` tests, builds and publishes to PyPI
|
|
140
|
+
via Trusted Publishing.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
knuckles_cli/__init__.py,sha256=gl_pwKunD6BzYHc1k8mxa8lNu7NI2iekXwTwyIVpixs,77
|
|
2
|
+
knuckles_cli/__main__.py,sha256=gKk3PaYVPtYZ-1Cc5jnLszklYk8n9N0UtAIxnWg39AU,105
|
|
3
|
+
knuckles_cli/api.py,sha256=Y2_5tmqtv9VOW7BCicbN5ZDF3jWcLZp56ZZjiybkeYc,7621
|
|
4
|
+
knuckles_cli/cli.py,sha256=ZQp0thnxEAa2IAQYtoUNA3VickxLXJNN_e1LR64e0No,21470
|
|
5
|
+
knuckles_cli/config.py,sha256=XkTawTEghEn4-bSyO-K_Eco-v2DPR51qHyRL_mo3qgg,6055
|
|
6
|
+
knuckles_cli/doctor.py,sha256=7aP-ZkOW4LfZ9V0nD3G5E9P9QURw8pu4cC0md1Ycr6w,7709
|
|
7
|
+
knuckles_cli/envfile.py,sha256=l70e9IfccfpG1jP87wc9FEa9Dxj6xiDL9hKouTNAGj4,3332
|
|
8
|
+
knuckles_cli/errors.py,sha256=3eotiKXI6tISnLldLehL_AguSE3Si3VZEDGIoivdBCs,1487
|
|
9
|
+
knuckles_cli/ops.py,sha256=4WfZtWdIBSwfiyFDqE-sJaBHLFuv4iFHHXX7Zvt8b10,13518
|
|
10
|
+
knuckles_cli/providers.py,sha256=ndd23ihp2yB1vNlevp3JkevyEmBOR8EXGte7Nk8CYac,11235
|
|
11
|
+
knuckles_cli/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
|
+
knuckles_cli-0.2.0.dist-info/licenses/LICENSE,sha256=G3I3YS3f75NFZsGp3VGqf8HXBIW_0IuBLgIf0ItkQoQ,1071
|
|
13
|
+
knuckles_cli-0.2.0.dist-info/METADATA,sha256=RjyqV5CMpVZIiEpSmCXgwZUhaZKZmHE8tlg50bNAARE,6363
|
|
14
|
+
knuckles_cli-0.2.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
15
|
+
knuckles_cli-0.2.0.dist-info/entry_points.txt,sha256=UgElgvj-0ORvf7xPooyGHWAsgOfoutcGzEbyNbjKUyM,51
|
|
16
|
+
knuckles_cli-0.2.0.dist-info/top_level.txt,sha256=lG62w5KqxscA4DgFU78MUjooPN9_eJnHAWn0U972nZ8,13
|
|
17
|
+
knuckles_cli-0.2.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Garrett Sooter
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
knuckles_cli
|