> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/continuous-integration/use-harness-ci/secure-harness-ci/authenticate-gcp-key-in-run-step.md).

# Use GCP secrets in scripts

This page explains how to handle JSON-formatted GCP credentials in scripts, such as in Run steps or Background steps. The information on this page **doesn't** apply to `.json` credentials supplied to [Harness GCP connectors](/harness-ai/use-harness-platform/connectors/cloud-providers/ref-cloud-providers/gcs-connector-settings-reference.md).

[Harness secrets](/harness-ai/use-harness-platform/secrets.md) with new line characters or other shell-interpreted special characters can cause errors in scripts you run in Harness pipelines. For example, attempting to parse a standard JSON-formatted GCP secret can cause errors such as `Could not read json file secret.json: Invalid control character at: line #, column #`.

To avoid these errors, you need to:

1. Run the following command to generate a base64-encoded version of your JSON file:

```bash
base64 <path-to-your-json-file> > encoded-secret.txt
```

2. Save the base64-encoded file as a [Harness file secret](/harness-ai/use-harness-platform/secrets/add-file-secrets.md).
3. In your pipeline, in the step where you need to use the GCP secret, decode the file secret and write it to a `.json` file. For example, this command decodes a Harness file secret named `my_secret` and writes it to `/harness/secrets.json`.

   ```
   echo <+secrets.getValue("my_secret")> | base64 --decode > /harness/secrets.json
   ```

   If your secret contains line breaks, you can `cat` the secret in a special-purpose code block, for example:

   ```
   cat > /harness/secrets.json << 'EOF'
   MySecret:<+secrets.getValue("my_secret")>
   EOF
   ```

   <div data-gb-custom-block data-tag="hint" data-style="warning" class="hint hint-warning"><p>Decoded secrets in <code>cat</code> aren't <a href="/spaces/3F2TpHXhur2QtQnORSM9/pages/9ERTIGamAgpPlplHIm7S#secrets-in-outputs">masked in outputs</a> because Harness no longer recognizes the contents as a secret.</p></div>
4. Use the `.json` file as needed for GCP authentication in your `gcloud` commands, such as:

   ```
   gcloud auth activate-service-account YOUR_SERVICE_ACCOUNT --key-file=/harness/secrets.json
   ```
