Should I rely on K6_CLOUD_TOKEN validation or explicit --out=cloud flag to prevent accidental public test exposure?
0 reputation · 15 Aug 2024, 10:26 UTC
0 reputation · 15 Aug 2024, 10:26 UTC
When running k6 load tests that target the cloud service, there's a risk of unintentionally exposing test scripts and results publicly. The k6 cloud command makes tests visible by default unless explicitly configured otherwise.
Two documented approaches exist for preventing this exposure: using the K6_CLOUD_TOKEN environment variable for secure authentication, or explicitly controlling output destinations via the --out flag.
The constraint is ensuring that local or CI/CD executions cannot accidentally publish tests to the public cloud dashboard. k6 v0.47.0+ introduced K6_CLOUD_TOKEN as the standard mechanism for authenticated cloud execution, while the --out=cloud flag provides explicit control over output destination. However, the behavior differs: setting K6_CLOUD_TOKEN to an empty or invalid value still allows local execution without public exposure, whereas omitting the flag entirely may trigger default cloud behavior.
Which approach provides stronger guarantees against accidental public exposure in automated environments?
26525 reputation · 15 Aug 2024, 14:26 UTC
To guarantee that a test cannot accidentally publish results to the public k6 Cloud dashboard, you must require both a valid authentication token and an explicit output directive.
K6_CLOUD_TOKEN environment variable only authenticates the client; it does not trigger any upload by itself.--out=cloud flag (or its script equivalent) tells k6 to send results to the cloud service; without this flag k6 runs locally and no data leaves the machine.In automated environments the risk is that a script or CI step unintentionally includes --out=cloud while a valid token is present (e.g., leaked from a shared secret store). When both conditions are true, k6 will authenticate and upload the test, making it visible in the Cloud UI. Conversely, having only one of the two conditions results in a safe outcome: a token without the flag yields a local run, and the flag without a valid token causes an authentication error and aborts the upload.
K6_CLOUD_TOKEN is set and non‑empty; treat an empty or missing value as a failure.--out=cloud flag (or out: cloud in a script) as part of the test invocation; do not rely on default behavior.If you can confirm that your CI system never exposes the token in logs, the combined validation alone is sufficient. If token leakage is a concern, you must add secret‑masking or short‑lived tokens to the workflow.
Use comments to ask for clarification. Post a solution as an answer.
26,525 reputation · 15 Aug 2024, 20:16 UTC
When both a valid K6_CLOUD_TOKEN and the --out=cloud flag are present, k6 authenticates and uploads the test to your private k6 Cloud project. The uploaded test remains private unless you manually change its visibility in the Cloud UI or via the API. Therefore, preventing accidental public exposure primarily means avoiding unintended uploads; token validation alone does not trigger upload, and the flag alone fails without a token.