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

feat(AWS Kafka): Add support for mTLS access configuration #10273

Merged
merged 6 commits into from
Dec 5, 2021
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
43 changes: 33 additions & 10 deletions lib/plugins/aws/package/compile/events/kafka.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const ServerlessError = require('../../../../../serverless-error');

class AwsCompileKafkaEvents {
constructor(serverless) {
this.serverless = serverless;
Expand Down Expand Up @@ -59,16 +61,6 @@ class AwsCompileKafkaEvents {
},
},
additionalProperties: false,
oneOf: [
{ required: ['vpcSubnet', 'vpcSecurityGroup'] },
{ required: ['saslPlainAuth'] },
{ required: ['saslScram256Auth'] },
{ required: ['saslScram512Auth'] },
{
required: ['clientCertificateTlsAuth'],
dependentRequired: { clientCertificateTlsAuth: ['serverRootCaCertificate'] },
},
],
},
batchSize: {
type: 'number',
Expand Down Expand Up @@ -132,6 +124,37 @@ class AwsCompileKafkaEvents {
functionObj.events.forEach((event) => {
if (!event.kafka) return;

if (!event.kafka.accessConfigurations || event.kafka.accessConfigurations.length === 0) {
mishabruml marked this conversation as resolved.
Show resolved Hide resolved
throw new ServerlessError(
`You must provide at least one accessConfiguration for function: ${functionName}`,
'FUNCTION_KAFKA_ACCESS_CONFIGURATION_EMPTY'
);
}

const {
accessConfigurations: {
vpcSecurityGroup,
vpcSubnet,
clientCertificateTlsAuth,
serverRootCaCertificate,
},
} = event.kafka;

if ((vpcSecurityGroup && !vpcSubnet) || (vpcSubnet && !vpcSecurityGroup)) {
mishabruml marked this conversation as resolved.
Show resolved Hide resolved
const missing = vpcSecurityGroup ? 'vpcSubnet' : 'vpcSecurityGroup';
throw new ServerlessError(
`You must specify at least one ${missing} accessConfiguration for function: ${functionName}`,
mishabruml marked this conversation as resolved.
Show resolved Hide resolved
`FUNCTION_KAFKA_VPC_ACCESS_CONFIGURATION_MISSING_${missing.toUpperCase()}`
mishabruml marked this conversation as resolved.
Show resolved Hide resolved
);
}

if (serverRootCaCertificate && !clientCertificateTlsAuth) {
throw new ServerlessError(
`You cannot specify serverRootCaCertificate accessConfiguration without providing a clientCertificateTlsAuth accessConfiguration for function: ${functionName}`,
mishabruml marked this conversation as resolved.
Show resolved Hide resolved
'FUNCTION_KAFKA_CLIENT_CERTIFICATE_TLS_AUTH_CONFIGURATION_MISSING'
);
}

hasKafkaEvent = true;
const { topic, batchSize, enabled } = event.kafka;
const startingPosition = event.kafka.startingPosition || 'TRIM_HORIZON';
Expand Down
Loading