Skip to content

Commit

Permalink
fix(api7): mismatch fields in upstream mtls (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
bzp2010 authored Nov 7, 2024
1 parent 9fb8200 commit 6746b9f
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 19 deletions.
2 changes: 1 addition & 1 deletion apps/cli/src/linter/exporter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Export jsonschema file by:
*
* $ ts-node apps/cli/src/linter/exporter.ts
* $ nx export-schema cli
*
*/
import { writeFileSync } from 'fs';
Expand Down
14 changes: 8 additions & 6 deletions apps/cli/src/linter/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,17 @@ const upstreamSchema = z
timeout: timeoutSchema.optional(),
tls: z
.object({
cert: z.string(),
key: z.string(),
client_cert_id: z.string(),
verify: z.boolean(),
client_cert: z.string().optional(),
client_key: z.string().optional(),
client_cert_id: z.string().optional(),
verify: z.boolean().optional(),
})
.strict()
.refine(
(data) =>
(data.cert && data.key && !data.client_cert_id) ||
(data.client_cert_id && !data.cert && !data.key),
(data.client_cert && data.client_key && !data.client_cert_id) ||
(data.client_cert_id && !data.client_cert && !data.client_key),
'The client_cert and client_key certificate pair or client_cert_id SSL reference ID must be set',
)
.optional(),
keepalive_pool: z
Expand Down
24 changes: 24 additions & 0 deletions apps/cli/src/linter/specs/upstream.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,30 @@ describe('Upstream Linter', () => {
} as ADCSDK.Configuration,
expect: true,
},
{
name: 'should only allow upstream mtls in client_cert and client_key',
input: {
services: [
{
name: 'Upstream mTLS',
upstream: {
nodes: [
{
host: '1.1.1.1',
port: 443,
weight: 100,
},
],
tls: {
client_cert: '0000',
client_key: '0000',
},
},
},
],
} as ADCSDK.Configuration,
expect: true,
},
];

// test cases runner
Expand Down
12 changes: 10 additions & 2 deletions libs/backend-api7/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,13 @@

| Features | Supported |
| ------------- | --------- |
| Dump to ADC ||
| Sync from ADC ||
| Dump to ADC ||
| Sync from ADC ||

## Supported Versions

| Versions | Supported |
| -------- | --------- |
| 3.2.14.6 ||
| 3.2.15.2 ||
| 3.2.16.2 ||
6 changes: 6 additions & 0 deletions libs/backend-api7/src/typing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ export interface Upstream {
retries?: number;
retry_timeout?: number;
timeout?: UpstreamTimeout;
tls?: {
client_cert: string;
client_key: string;
client_cert_id: string;
verify: boolean;
};
keepalive_pool?: {
size: number;
idle_timeout: number;
Expand Down
4 changes: 2 additions & 2 deletions libs/sdk/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ export interface UpstreamTimeout {
read: number;
}
export interface UpstreamClientTLS {
cert: string;
key: string;
client_cert: string;
client_key: string;
client_cert_id: string;
verify: boolean;
}
Expand Down
10 changes: 2 additions & 8 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,10 @@
"tls": {
"type": "object",
"properties": {
"cert": {
"client_cert": {
"type": "string"
},
"key": {
"client_key": {
"type": "string"
},
"client_cert_id": {
Expand All @@ -325,12 +325,6 @@
"type": "boolean"
}
},
"required": [
"cert",
"key",
"client_cert_id",
"verify"
],
"additionalProperties": false
},
"keepalive_pool": {
Expand Down

0 comments on commit 6746b9f

Please sign in to comment.