Enhancing Credential Configuration in CRDs: Leveraging Environment Variables #660
Replies: 8 comments 22 replies
-
Hey @geoffrey1330, thanks for taking the lead on this. I definitely have use cases for this feature and I’ve been watching the issue for a while. I like the idea of using the existing ConfigMap pattern in Deployments. This is definitely a more k8s native approach. I would also consider maintaining compatibility with existing Tyk KV secrets storage so external KV stores can still be used. This would prevent any incompatibility issues when migrating from JSON API definitions. Let me see if I can create some test API definitions based on my use cases. |
Beta Was this translation helpful? Give feedback.
-
Here's a use case I encounter quite often. apiVersion: tyk.tyk.io/v1alpha1
kind: ApiDefinition
metadata:
name: httpbin-bearer
spec:
name: httpbin-bearer
use_keyless: true
protocol: http
active: true
proxy:
target_url: http://httpbin.org/bearer
listen_path: /httpbin/bearer
strip_listen_path: true
version_data:
default_version: Default
not_versioned: true
versions:
Default:
name: Default
global_headers:
authorization: $secret_env.httpbin_bearer_auth |
Beta Was this translation helpful? Give feedback.
-
Hi @buraksekili I have created a PR for the api structure here |
Beta Was this translation helpful? Give feedback.
-
Thank you for raising this concern. Presently, we employ Kubernetes Secret references for specific fields like PinnedPublicKeysRefs, which are not part of the typical API Definition within Tyk. When the operator detects these fields with populated values, it retrieves the corresponding secret from Kubernetes. Subsequently, it creates a secret within Tyk using Tyk APIs and uses the ID of the newly created secret in the APIDefinition. To illustrate this operation more explicitly, here's a rough scenario: # apidefinition.yaml
spec:
fooRef: mysecret Upon applying this manifest, the operator:
Consequently, the resulting structure becomes: # apidefinition.yaml
spec:
fooRef: mysecret
foo: 123 This flow allows your API to successfully utilize your Kubernetes secret. The challenge I've observed while employing secrets in Config Data is due to its nature as an arbitrary JSON, as outlined here. As it lacks a JSON schema, we face difficulty in marshaling the structure into a Go structure to inherently comprehend Kubernetes references within it. While we could consider hacky solutions to support this concept, it might restrict the potential use cases of Config Data, which we aim to avoid. Thus, we are unable to directly reference a secret using fields like |
Beta Was this translation helpful? Give feedback.
-
Hi @buraksekili base on the look of things the env approach might not be the best solution. i.e
|
Beta Was this translation helpful? Give feedback.
-
Hi @buraksekili i'm facing some difficulties try to deploy the operator for development purposes so i could test my implementation. |
Beta Was this translation helpful? Give feedback.
-
Hi @buraksekili what do you think about this new approach. The Approach will address concerns related to parsing Unstructured data by using a recursive traversal approach to handle nested structures with values stored as interface{}. Additionally, it identifies secretRef by checking for the presence of a field with that name in the Unstructured data. Once secretRef is detected, it retrieves the secret based on the specified name and key within the secretRef. |
Beta Was this translation helpful? Give feedback.
-
What if this feature were implemented as a k8s KV store in Tyk Gateway that could read values from Secret resources? Secret values could be referenced in ApiDefinitions using The benefits to this approach are:
The main con to this approach is it requires multiple changes to Tyk Gateway (e.g., new k8s KV store, new labels in mw_url_rewrite.go, new k8s store config). I'm curious if there's a better way to implement a new KV store that doesn't require so many code changes. |
Beta Was this translation helpful? Give feedback.
-
Description:
This discussion centers around improving the management of credential configurations in Kubernetes Custom Resource Definitions (CRDs), particularly addressing the need to securely handle sensitive information like API keys within the CRD's YAML files. Currently, there's a requirement to place such credentials in the config_data section of an API definition within CRDs.
Objective:
The primary goal is to explore better ways to handle credentials and secrets in CRDs to enhance security and ease of use. It would be beneficial to discuss potential solutions and existing methods.
Proposed Approach:
One potential approach to consider is adopting a mechanism similar to how Kubernetes handles secrets and ConfigMaps in Deployments. This could include leveraging environment variables in CRD YAML files for secure credential management.
i.e
Beta Was this translation helpful? Give feedback.
All reactions