7878#define FLB_OCI_MATCH_PREFIX "oci_match_"
7979#define FLB_OCI_MATCH_PREFIX_SIZE sizeof(FLB_OCI_MATCH_PREFIX)-1
8080
81+ #define FLB_OCI_LOG_TIMEZONE_KEY "oci_la_timezone"
82+ #define FLB_OCI_LOG_TIMEZONE_KEY_SIZE sizeof(FLB_OCI_LOG_TIMEZONE_KEY) - 1
83+
84+ #define FLB_OCI_LOG_TIMEZONE "timezone"
85+ #define FLB_OCI_LOG_TIMEZONE_SIZE sizeof(FLB_OCI_LOG_TIMEZONE) - 1
86+
8187#ifdef FLB_HAVE_REGEX
8288#define FLB_OCI_MATCH_REGEX_PREFIX "oci_match_regex_"
8389#define FLB_OCI_MATCH_REGEX_PREFIX_SIZE sizeof(FLB_OCI_MATCH_REGEX_PREFIX)-1
97103#define FLB_OCI_PARAM_INCLUDE_COLLECT_TIME "include_collect_time"
98104#define FLB_OCI_PARAM_INCLUDE_COLLECT_TIME_SIZE sizeof(FLB_OCI_PARAM_INCLUDE_COLLECT_TIME)-1
99105
100- #define FLB_OCI_MATCH_ID_MAX 1000 // TO avoid too large memory allocation
106+ #define FLB_OCI_MATCH_ID_MAX 1000 // TO avoid too large memory allocation
101107
102108#define FLB_OCI_DEFAULT_COLLECT_TIME "oci_collect_time"
103109#define FLB_OCI_DEFAULT_COLLECT_TIME_SIZE sizeof(FLB_OCI_DEFAULT_COLLECT_TIME)-1
150156#define FLB_OCI_ERROR_CODE_TOO_MANY_REQUESTS "TooManyRequests"
151157#define FLB_OCI_ERROR_CODE_INTERNAL_SERVER_ERROR "InternalServerError"
152158
159+ /* for imds request*/
160+ #define ORACLE_IMDS_HOST "169.254.169.254"
161+ #define ORACLE_IMDS_BASE_URL "/opc/v2"
162+ #define ORACLE_IMDS_REGION_PATH "/instance/region"
163+ #define ORACLE_IMDS_LEAF_CERT_PATH "/identity/cert.pem"
164+ #define ORACLE_IMDS_LEAF_KEY_PATH "/identity/key.pem"
165+ #define ORACLE_IMDS_INTERMEDIATE_CERT_PATH "/identity/intermediate.pem"
166+ #define ORACLE_AUTH_HEADER "Authorization: Bearer Oracle"
167+ #define ORACLE_IMDS_TOKEN_PATH "/opc/v2/instancePrincipal/token"
168+
169+
170+ #define COUNT_OF_REGION (sizeof(region_mappings) / sizeof(region_mappings[0]) - 1)
171+
172+ /* for chunking */
173+ #define MAX_PAYLOAD_SIZE_BYTES (3800000) // 3.8 mb
174+
153175#include <fluent-bit/flb_upstream.h>
154176#include <fluent-bit/flb_sds.h>
155177#include <fluent-bit/flb_record_accessor.h>
156178#include <fluent-bit/flb_hash_table.h>
179+ #include <fluent-bit/flb_output_plugin.h>
180+ #include <fluent-bit/flb_upstream.h>
181+ #include <fluent-bit/flb_upstream_conn.h>
182+ #include <fluent-bit/flb_http_client.h>
183+ #include <fluent-bit/flb_log_event_decoder.h>
184+ #include <fluent-bit/flb_hash_table.h>
185+ #include <fluent-bit/flb_pack.h>
186+ #include <fluent-bit/flb_crypto.h>
187+ #include <fluent-bit/flb_base64.h>
188+ #include <fluent-bit/flb_hash.h>
189+ #include <fluent-bit/flb_sds.h>
157190#include <monkey/mk_core/mk_list.h>
158-
159- struct metadata_obj {
191+ #include <fluent-bit/flb_jsmn.h>
192+ #include <openssl/evp.h>
193+ #include <openssl/pem.h>
194+ #include <openssl/bio.h>
195+ #include <openssl/buffer.h>
196+ #include <openssl/opensslv.h>
197+ #include <openssl/err.h>
198+ #include <openssl/x509v3.h>
199+ #include <openssl/x509.h>
200+ #include <openssl/rsa.h>
201+ #include <msgpack.h>
202+ #include <string.h>
203+
204+ struct metadata_obj
205+ {
160206 flb_sds_t key ;
161207 flb_sds_t val ;
162208 struct mk_list _head ;
@@ -165,23 +211,65 @@ struct metadata_obj {
165211
166212struct flb_oci_error_response
167213{
168- flb_sds_t code ;
169- flb_sds_t message ;
214+ flb_sds_t code ;
215+ flb_sds_t message ;
216+ };
217+
218+ struct flb_oracle_imds
219+ {
220+ flb_sds_t region ;
221+ flb_sds_t leaf_cert ;
222+ flb_sds_t leaf_key ;
223+ flb_sds_t intermediate_cert ;
224+ flb_sds_t tenancy_ocid ;
225+ flb_sds_t fingerprint ;
226+ flb_sds_t session_pubkey ;
227+ flb_sds_t session_privkey ;
228+ struct flb_upstream * upstream ;
229+ struct flb_output_instance * ins ;
170230};
171231
172- struct flb_oci_logan {
232+ struct oci_security_token
233+ {
234+ flb_sds_t token ;
235+ time_t expires_at ;
236+ flb_sds_t session_privkey ;
237+ };
238+
239+ typedef struct
240+ {
241+ const char * region ;
242+ const char * realm ;
243+ } region_realm_mapping_t ;
244+
245+ typedef struct
246+ {
247+ const char * short_name ;
248+ const char * long_name ;
249+ } region_mapping_t ;
250+
251+ typedef struct
252+ {
253+ const char * realm_code ;
254+ const char * domain_suffix ;
255+ } realm_mapping_t ;
256+
257+ struct flb_oci_logan
258+ {
173259 flb_sds_t namespace ;
174260 flb_sds_t config_file_location ;
175261 flb_sds_t profile_name ;
176262 int oci_config_in_record ;
177263 flb_sds_t uri ;
178264
265+ char * domain_suffix ;
179266 struct flb_upstream * u ;
180267 flb_sds_t proxy ;
181268 char * proxy_host ;
182269 int proxy_port ;
183270
184271 // oci_la_* configs
272+
185273 flb_sds_t oci_la_entity_id ;
186274
187275 flb_sds_t oci_la_entity_type ;
@@ -194,22 +282,37 @@ struct flb_oci_logan {
194282
195283 flb_sds_t oci_la_log_set_id ;
196284
285+ flb_sds_t oci_la_timezone ;
286+
197287 struct mk_list * oci_la_global_metadata ;
198288 struct mk_list global_metadata_fields ;
199289 struct mk_list * oci_la_metadata ;
200290 struct mk_list log_event_metadata_fields ;
201291
202- // config_file
292+ // config_file
203293 flb_sds_t user ;
204294 flb_sds_t region ;
205295 flb_sds_t tenancy ;
206296 flb_sds_t key_fingerprint ;
207297 flb_sds_t key_file ;
208298 /* For OCI signing */
209- flb_sds_t key_id ; // tenancy/user/key_fingerprint
299+ flb_sds_t key_id ; // tenancy/user/key_fingerprint
210300 flb_sds_t private_key ;
211-
212301 struct flb_output_instance * ins ;
213302
303+ // instance prinicipal auth
304+ struct flb_oracle_imds imds ;
305+ EVP_PKEY * session_key_pair ;
306+ struct oci_security_token security_token ;
307+ char * auth_type ;
308+
309+ // dump payload
310+ char * payload_files_location ;
311+ bool dump_payload_file ;
214312};
313+
314+ int is_valid_timezone (const char * log_timezone );
315+ const char * get_domain_suffix_for_realm (const char * realm );
316+ const char * determine_realm_from_region (const char * region );
317+ const char * long_region_name (char * short_region_name );
215318#endif
0 commit comments