Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document GPRC Connection's TLS option #1290

Merged
merged 6 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,20 @@ See [Client.close()](/javascript-api/k6-experimental/grpc/client/client-close) t
| `ConnectParams.plaintext` | bool | If `true` will connect to the gRPC server using plaintext i.e. insecure. Defaults to `false` i.e. secure via TLS. |
| `ConnectParams.reflect` | boolean | Whether to use the [gRPC server reflection protocol](https://github.com/grpc/grpc/blob/master/doc/server-reflection.md) when connecting. |
| `ConnectParams.timeout` | string / number | Connection timeout to use. Default timeout is `"60s"`. <br/> The type can also be a number, in which case k6 interprets it as milliseconds, e.g., `60000` is equivalent to `"60s"`. |
| `ConnectParams.maxReceiveSize` | number | Sets the maximum message size in bytes the client can receive.Defaults to 0. |
| `ConnectParams.maxSendSize` | number | Sets the maximum message size in bytes the client can send.Defaults to 0. |
| `ConnectParams.maxReceiveSize` | number | Sets the maximum message size in bytes the client can receive. Defaults to 0. |
| `ConnectParams.maxSendSize` | number | Sets the maximum message size in bytes the client can send. Defaults to 0. |
| `ConnectParams.tls` (optional) | object | [TLS](#tls) | TLS settings of the connection. Defaults not defined. |
heitortsergent marked this conversation as resolved.
Show resolved Hide resolved
olegbespalov marked this conversation as resolved.
Show resolved Hide resolved

## TLS

TLS settings of the connection, if not defined, the main TLS config from options will be used.
olegbespalov marked this conversation as resolved.
Show resolved Hide resolved

| Name | Type | Description |
|------|------|-------------|
| `tls.cert` | string | PEM formatted client certificate. |
| `tls.key` | string | PEM formatted client private key. |
| `tls.password` | string | Password for decrypting the client's private key. |
| `tls.cacerts` | string / array | PEM formatted strings of the certificate authorities. |

### Examples

Expand Down Expand Up @@ -50,3 +62,69 @@ export default () => {
};
```
</div>

<div class="code-group" data-props='{"labels": ["Different TLS settings"], "lineNumbers": [true]}'>

```javascript
import grpc from 'k6/experimental/grpc';
import { check } from 'k6';

// note: there are no such services
olegbespalov marked this conversation as resolved.
Show resolved Hide resolved
const params = {
'foo1.grpcbin.test.k6.io:9001': {
plaintext: false,
tls: {
cacerts: [open('cacerts0.pem')],
cert: open('cert0.pem'),
key: open('key0.pem'),
},
},
'foo2.grpcbin.test.k6.io:9002': {
plaintext: false,
tls: {
cacerts: open('cacerts1.pem'),
cert: open('cert1.pem'),
key: open('key1.pem'),
password: 'cert1-passphrase',
},
},
};
const clients = {
'foo1.grpcbin.test.k6.io:9001': new grpc.Client(),
'foo2.grpcbin.test.k6.io:9002': new grpc.Client(),
};

export default () => {
if (__ITER === 0) {
clients['foo1.grpcbin.test.k6.io:9001'].connect(
'foo1.grpcbin.test.k6.io:9001',
params['foo1.grpcbin.test.k6.io:9001']
);
clients['foo2.grpcbin.test.k6.io:9002'].connect(
'foo2.grpcbin.test.k6.io:9002',
params['foo2.grpcbin.test.k6.io:9002']
);
}

const response1 = clients['foo1.grpcbin.test.k6.io:9001'].invoke('hello.HelloService/SayHello', {
greeting: 'Bert',
});

check(response1, {
'status is OK': (r) => r && r.status === grpc.StatusOK,
});

console.log(JSON.stringify(response1.message));

const response2 = clients['foo2.grpcbin.test.k6.io:9002'].invoke('hello.HelloService/SayHello', {
greeting: 'Ernie',
});

check(response2, {
'status is OK': (r) => r && r.status === grpc.StatusOK,
});

console.log(JSON.stringify(response2.message));
};
```
heitortsergent marked this conversation as resolved.
Show resolved Hide resolved
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,20 @@ See [Client.close()](/javascript-api/k6-net-grpc/client/client-close) to close t
| `ConnectParams.plaintext` | bool | If `true` will connect to the gRPC server using plaintext i.e. insecure. Defaults to `false` i.e. secure via TLS. |
| `ConnectParams.reflect` | boolean | Whether to use the [gRPC server reflection protocol](https://github.com/grpc/grpc/blob/master/doc/server-reflection.md) when connecting. |
| `ConnectParams.timeout` | string / number | Connection timeout to use. Default timeout is `"60s"`. <br/> The type can also be a number, in which case k6 interprets it as milliseconds, e.g., `60000` is equivalent to `"60s"`. |
| `ConnectParams.maxReceiveSize` | number | Sets the maximum message size in bytes the client can receive.Defaults to 0. |
| `ConnectParams.maxSendSize` | number | Sets the maximum message size in bytes the client can send.Defaults to 0. |
| `ConnectParams.maxReceiveSize` | number | Sets the maximum message size in bytes the client can receive. Defaults to 0. |
| `ConnectParams.maxSendSize` | number | Sets the maximum message size in bytes the client can send. Defaults to 0. |
| `ConnectParams.tls` (optional) | object | [TLS](#tls) | TLS settings of the connection. Defaults not defined. |
heitortsergent marked this conversation as resolved.
Show resolved Hide resolved
olegbespalov marked this conversation as resolved.
Show resolved Hide resolved

## TLS

TLS settings of the connection, if not defined, the main TLS config from options will be used.
olegbespalov marked this conversation as resolved.
Show resolved Hide resolved

| Name | Type | Description |
|------|------|-------------|
| `tls.cert` | string | PEM formatted client certificate. |
| `tls.key` | string | PEM formatted client private key. |
| `tls.password` | string | Password for decrypting the client's private key. |
| `tls.cacerts` | string / array | PEM formatted strings of the certificate authorities. |

### Examples

Expand Down Expand Up @@ -50,3 +62,69 @@ export default () => {
};
```
</div>

<div class="code-group" data-props='{"labels": ["Different TLS settings"], "lineNumbers": [true]}'>

```javascript
import grpc from 'k6/net/grpc';
import { check } from 'k6';

// note: there are no such services
const params = {
'foo1.grpcbin.test.k6.io:9001': {
plaintext: false,
tls: {
cacerts: [open('cacerts0.pem')],
cert: open('cert0.pem'),
key: open('key0.pem'),
},
},
'foo2.grpcbin.test.k6.io:9002': {
plaintext: false,
tls: {
cacerts: open('cacerts1.pem'),
cert: open('cert1.pem'),
key: open('key1.pem'),
password: 'cert1-passphrase',
},
},
};
const clients = {
'foo1.grpcbin.test.k6.io:9001': new grpc.Client(),
'foo2.grpcbin.test.k6.io:9002': new grpc.Client(),
};

export default () => {
if (__ITER === 0) {
clients['foo1.grpcbin.test.k6.io:9001'].connect(
'foo1.grpcbin.test.k6.io:9001',
params['foo1.grpcbin.test.k6.io:9001']
);
clients['foo2.grpcbin.test.k6.io:9002'].connect(
'foo2.grpcbin.test.k6.io:9002',
params['foo2.grpcbin.test.k6.io:9002']
);
}

const response1 = clients['foo1.grpcbin.test.k6.io:9001'].invoke('hello.HelloService/SayHello', {
greeting: 'Bert',
});

check(response1, {
'status is OK': (r) => r && r.status === grpc.StatusOK,
});

console.log(JSON.stringify(response1.message));

const response2 = clients['foo2.grpcbin.test.k6.io:9002'].invoke('hello.HelloService/SayHello', {
greeting: 'Ernie',
});

check(response2, {
'status is OK': (r) => r && r.status === grpc.StatusOK,
});

console.log(JSON.stringify(response2.message));
};
oleiade marked this conversation as resolved.
Show resolved Hide resolved
```
</div>
Loading