Skip to content

Commit eede514

Browse files
committed
tenants
1 parent dfa2281 commit eede514

File tree

5 files changed

+33
-35
lines changed

5 files changed

+33
-35
lines changed

api/4/tenants.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,27 @@ The Tenants API **requires** a key which can be generated using the [Tenants CLI
1212

1313
## Request signing
1414

15-
Requests to the Tenants API **must** be signed by passing the `X-Signature` header containing the request signature.
15+
All requests to the Tenants API **must** include an `X-Signature` header containing an HMAC SHA256 signature of the request body.
1616

1717
```plain
18-
X-Signature: request_signature_here
18+
X-Signature: your_hmac_sha256_signature
1919
```
2020

21-
Signatures must be generated using the raw request body string and the [Tenants Private Key](../../application/configuration/multitenancy.md#tenants-key-pair), with base64 encoding.
21+
Generate the signature by hashing the raw request body (as a string) with `CHEVERETO_TENANTS_API_SIGNING_SECRET` using HMAC SHA256. The output must be in hexadecimal format.
2222

23+
<code-group>
24+
<code-block title="PHP">
2325
```php
24-
$signed = $privateKey->sign($body);
25-
$signature = base64_encode($signed);
26+
$signature = hash_hmac('sha256', $body, 'your_request_secret');
2627
```
28+
</code-block>
29+
30+
<code-block title="Shell">
31+
```sh
32+
echo -n 'body string' | openssl dgst -sha256 -hmac 'your_request_secret' -r | awk '{print $1}'
33+
```
34+
</code-block>
35+
</code-group>
2736

2837
## `/_/api/4/tenants`
2938

application/configuration/configuring.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ return [
147147
'CHEVERETO_TENANT' => '',
148148
'CHEVERETO_TENANT_ENFORCED' => '{}',
149149
'CHEVERETO_TENANTS_API_ALLOW_LIST' => '',
150-
'CHEVERETO_TENANTS_PUBLIC_KEY' => '',
151-
'CHEVERETO_TENANTS_API_KEY_SIGNING_SECRET' => '',
150+
'CHEVERETO_TENANTS_API_KEY_SECRET' => '',
151+
'CHEVERETO_TENANTS_API_REQUEST_SECRET' => '',
152152
'CHEVERETO_XRDEBUG_HOST' => 'localhost',
153153
'CHEVERETO_XRDEBUG_HTTPS' => '0',
154154
'CHEVERETO_XRDEBUG_KEY' => '',

application/configuration/environment.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,16 @@ Environment variables for configuring the service provider.
137137

138138
Environment variables for configuring multi-tenancy.
139139

140-
| Variable | Example |
141-
| ---------------------------------------- | ------------------------------- |
142-
| CHEVERETO_TENANTS_PUBLIC_KEY | your_tenants_public_key |
143-
| CHEVERETO_TENANTS_API_KEY_SIGNING_SECRET | your_tenants_api_signing_secret |
144-
| CHEVERETO_TENANTS_API_ALLOW_LIST | 200.200.200.200,10.0.0.0/24 |
145-
| CHEVERETO_TENANT_ENFORCED | {"CHEVERETO_MAX_USERS":"100"} |
146-
| CHEVERETO_TENANT | tenant1 |
147-
148-
* `CHEVERETO_TENANTS_PUBLIC_KEY` is used to sign requests to the [Tenants API](../../api/4/tenants.md).
149-
* `CHEVERETO_TENANTS_API_KEY_SIGNING_SECRET` is used to verify requests coming from a known [Tenants API](../../api/4/tenants.md) key.
140+
| Variable | Example |
141+
| ------------------------------------ | ----------------------------- |
142+
| CHEVERETO_TENANTS_API_REQUEST_SECRET | your_request_secret |
143+
| CHEVERETO_TENANTS_API_KEY_SECRET | your_key_secret |
144+
| CHEVERETO_TENANTS_API_ALLOW_LIST | 200.200.200.200,10.0.0.0/24 |
145+
| CHEVERETO_TENANT_ENFORCED | {"CHEVERETO_MAX_USERS":"100"} |
146+
| CHEVERETO_TENANT | tenant1 |
147+
148+
* `CHEVERETO_TENANTS_API_REQUEST_SECRET` is used to sign requests to the [Tenants API](../../api/4/tenants.md).
149+
* `CHEVERETO_TENANTS_API_KEY_SECRET` is used to verify requests coming from a known [Tenants API](../../api/4/tenants.md) key.
150150
* `CHEVERETO_TENANTS_API_ALLOW_LIST` is used to restrict access to the [Tenants API](../../api/4/tenants.md) by IP address or network.
151151
* `CHEVERETO_TENANT_ENFORCED` is a JSON object that defines which variables will be enforced (overridden) for the multi-tenant context.
152152
* `CHEVERETO_TENANT` is intended to be used to pass the current tenant context for CLI.

application/configuration/multitenancy.md

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,10 @@ CHEVERETO_ENABLE_TENANTS=1
3636
CHEVERETO_ENCRYPTION_KEY=your_encryption_key
3737
CHEVERETO_PROVIDER_NAME=your_provider_name
3838
CHEVERETO_PROVIDER_URL=your_provider_url
39+
CHEVERETO_TENANTS_API_REQUEST_SECRET=your_request_secret
3940
```
4041

41-
### Tenants key pair
42-
43-
If you need to use the [Tenants API](../../api/4/tenants.md), you will require a key pair. You must set a Tenants public key for verifying signed requests.
44-
45-
```plain
46-
CHEVERETO_TENANTS_PUBLIC_KEY=your_tenants_public_key
47-
```
48-
49-
To generate a key pair, you can use `ssh-keygen`:
50-
51-
```sh
52-
ssh-keygen -t ed25519 -C "your_email@example.com" -f tenants_key
53-
```
42+
* `CHEVERETO_TENANTS_API_REQUEST_SECRET` is required to verify signed requests to the [Tenants API](../../api/4/tenants.md).
5443

5544
### SaaS context
5645

@@ -150,11 +139,11 @@ app/bin/tenants -C api:key:delete --name "My Key"
150139

151140
Access to the [Tenants API](../../api/4/tenants.md) can be restricted by IP address or network range using `CHEVERETO_TENANTS_API_ALLOW_LIST`.
152141

153-
All API keys are cryptographically signed with `CHEVERETO_TENANTS_API_KEY_SIGNING_SECRET`. Only keys generated through the [Tenants CLI](../../application/reference/cli.md#create-tenants-api-key) contain valid signatures and will be accepted by the API.
142+
All API keys are cryptographically signed with `CHEVERETO_TENANTS_API_KEY_SECRET`. Only keys generated through the [Tenants CLI](../../application/reference/cli.md#create-tenants-api-key) contain valid signatures and will be accepted by the API.
154143

155144
```plain
156145
CHEVERETO_TENANTS_API_ALLOW_LIST="200.200.200.200,10.0.0.0/24,203.0.113.0/28"
157-
CHEVERETO_TENANTS_API_KEY_SIGNING_SECRET=your_tenants_api_signing_secret
146+
CHEVERETO_TENANTS_API_KEY_SECRET=your_tenants_api_signing_secret
158147
```
159148

160149
## Managing tenant plans

introduction/changelog/4.4.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ This variable allows defining a JSON object with environment variables that will
2222

2323
When running Chevereto in multi-tenant mode, this variable specifies the target tenant for command-line interface (CLI) operations. It should be set to the unique tenant ID of the desired tenant.
2424

25-
`CHEVERETO_TENANTS_PUBLIC_KEY`
25+
`CHEVERETO_TENANTS_API_REQUEST_SECRET`
2626

27-
This variable is required to verify signed requests to the [Tenants API](../../api/4/tenants.md). It should contain the public key corresponding to the private key used for signing requests.
27+
This variable is required to verify signed requests to the [Tenants API](../../api/4/tenants.md). It should contain the secret used for signing requests.
2828

2929
`CHEVERETO_TENANTS_API_ALLOW_LIST`
3030

3131
This variable allows restricting access to the [Tenants API](../../api/4/tenants.md) by specifying a comma-separated list of allowed IP addresses or networks. Only requests originating from these sources will be permitted to access the API.
3232

33-
`CHEVERETO_TENANTS_API_KEY_SIGNING_SECRET`
33+
`CHEVERETO_TENANTS_API_KEY_SECRET`
3434

3535
This variable is used to verify requests coming from a known [Tenants API](../../api/4/tenants.md) key.
3636

0 commit comments

Comments
 (0)