|
25 | 25 | #include <fluent-bit/flb_config_map.h> |
26 | 26 | #include <fluent-bit/flb_aws_util.h> |
27 | 27 | #include <fluent-bit/aws/flb_aws_compress.h> |
| 28 | +#include <fluent-bit/aws/flb_aws_sse.h> |
28 | 29 | #include <fluent-bit/flb_hash.h> |
29 | 30 | #include <fluent-bit/flb_crypto.h> |
30 | 31 | #include <fluent-bit/flb_signv4.h> |
@@ -98,6 +99,13 @@ static struct flb_aws_header storage_class_header = { |
98 | 99 | .val_len = 0, |
99 | 100 | }; |
100 | 101 |
|
| 102 | +static struct flb_aws_header server_side_encryption_header = { |
| 103 | + .key = "x-amz-server-side-encryption", |
| 104 | + .key_len = 28, |
| 105 | + .val = "", |
| 106 | + .val_len = 0, |
| 107 | +}; |
| 108 | + |
101 | 109 | static char *mock_error_response(char *error_env_var) |
102 | 110 | { |
103 | 111 | char *err_val = NULL; |
@@ -150,6 +158,9 @@ int create_headers(struct flb_s3 *ctx, char *body_md5, |
150 | 158 | if (body_md5 != NULL && strlen(body_md5) && multipart_upload == FLB_FALSE) { |
151 | 159 | headers_len++; |
152 | 160 | } |
| 161 | + if (strlen(ctx->sse)) { |
| 162 | + headers_len++; |
| 163 | + } |
153 | 164 | if (ctx->storage_class != NULL) { |
154 | 165 | headers_len++; |
155 | 166 | } |
@@ -187,6 +198,12 @@ int create_headers(struct flb_s3 *ctx, char *body_md5, |
187 | 198 | s3_headers[n].val_len = strlen(body_md5); |
188 | 199 | n++; |
189 | 200 | } |
| 201 | + if (strlen(ctx->sse)) { |
| 202 | + s3_headers[n] = server_side_encryption_header; |
| 203 | + s3_headers[n].val = ctx->sse; |
| 204 | + s3_headers[n].val_len = strlen(ctx->sse); |
| 205 | + n++; |
| 206 | + } |
190 | 207 | if (ctx->storage_class != NULL) { |
191 | 208 | s3_headers[n] = storage_class_header; |
192 | 209 | s3_headers[n].val = ctx->storage_class; |
@@ -756,6 +773,16 @@ static int cb_s3_init(struct flb_output_instance *ins, |
756 | 773 | } |
757 | 774 | } |
758 | 775 |
|
| 776 | + tmp = flb_output_get_property("server_side_encryption", ins); |
| 777 | + if (tmp) { |
| 778 | + ret = flb_aws_sse_get_type(tmp); |
| 779 | + if (ret == -1) { |
| 780 | + flb_plg_error(ctx->ins, "unknown server-side encryption type: %s", tmp); |
| 781 | + return -1; |
| 782 | + } |
| 783 | + ctx->sse = tmp; |
| 784 | + } |
| 785 | + |
759 | 786 | tmp = flb_output_get_property("sts_endpoint", ins); |
760 | 787 | if (tmp) { |
761 | 788 | ctx->sts_endpoint = (char *) tmp; |
@@ -2376,7 +2403,12 @@ static struct flb_config_map config_map[] = { |
2376 | 2403 | "A standard MIME type for the S3 object; this will be set " |
2377 | 2404 | "as the Content-Type HTTP header." |
2378 | 2405 | }, |
2379 | | - |
| 2406 | + { |
| 2407 | + FLB_CONFIG_MAP_STR, "server_side_encryption", NULL, |
| 2408 | + 0, FLB_FALSE, 0, |
| 2409 | + "Optional serve-side encryption type to use" |
| 2410 | + "Defaults to no encryption header. " |
| 2411 | + }, |
2380 | 2412 | { |
2381 | 2413 | FLB_CONFIG_MAP_STR, "store_dir", "/tmp/fluent-bit/s3", |
2382 | 2414 | 0, FLB_TRUE, offsetof(struct flb_s3, store_dir), |
|
0 commit comments