Skip to content

Conversation

@cognifloyd
Copy link
Member

datastore_crypto_key and st2chatops secrets are both likely to have non-string content.
Examples:

  • Using YAML or plain JSON formatting for datastore_crypto_key in values instead of a JSON-encoded string wrapped in single quotes.
  • Using an integer for one of the chatops env vars (like ST2_COMMANDS_RELOAD_INTERVAL: 10 instead of ST2_COMMANDS_RELOAD_INTERVAL: "10")

We can easily cast these to string in the secret templates to fix this.

Resolves #229

@cognifloyd cognifloyd added bug Something isn't working RFR labels Sep 6, 2021
@cognifloyd cognifloyd requested a review from arm4b September 6, 2021 14:48
@pull-request-size pull-request-size bot added the size/XS PR that changes 0-9 lines. Quick fix/merge. label Sep 6, 2021
@cognifloyd cognifloyd enabled auto-merge September 6, 2021 14:48
@cognifloyd
Copy link
Member Author

@armab I would like to include this one in the next release as well.

{{- if kindIs "string" .Values.st2.datastore_crypto_key }}
datastore_crypto_key: {{ .Values.st2.datastore_crypto_key | b64enc }}
{{- else }}
datastore_crypto_key: {{ .Values.st2.datastore_crypto_key | toJson | b64enc }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't add an option for users to shoot themselves in their foot.
Datastore crypto key is an artifact that you generate and copy-paste, instead of trying to split it into pieces or re-format with yaml.

Copy link
Member Author

@cognifloyd cognifloyd Sep 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I shot myself in the foot. JSON is valid YAML. If you don't surround what you copy/paste with single quotes, it will be parsed into a dictionary and then things break.
This change makes the chart more forgiving.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. This change makes those instructions valid.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change the Helm values instructions? Similar to what we had for SSH key

datastore_crypto_key: |
  {"hmacKey": {"hmacKeyString": "", "size": 256}, "size": 256, "aesKeyString": "", "mode": "CBC"} 

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.
Which part of this change do you dislike? The kindIs "String" check, or passing the value through toJson?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the PR to drop toJson here and update the docs in values.yaml instead.

I would still like to understand your intuition - Why/how does serializing the datastore_crypto_key create "an option for users to shoot themselves in their foot"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it comes from the expectations that the datastore crypto key is an immutable artifact that users just generate and copy-paste, instead of trying to split it into pieces, re-format, or modify. So it's best to keep that piece of data as is to avoid any further confusion or corner cases.

data:
{{- range $env, $value := .Values.st2chatops.env }}
{{ $env }}: {{ $value | b64enc | quote }}
{{ $env }}: {{ $value | toString | b64enc | quote }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks good to me

@cognifloyd cognifloyd merged commit 78e57fe into StackStorm:master Sep 8, 2021
Copy link
Member

@arm4b arm4b left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot!

@cognifloyd cognifloyd changed the title Automatically stringify st2.datastore_crypto_key and st2chatop.env values Ensure st2.datastore_crypto_key and st2chatop.env values are strings Sep 8, 2021
@cognifloyd cognifloyd removed the RFR label Sep 12, 2021
@cognifloyd cognifloyd deleted the stringify branch November 11, 2021 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size/XS PR that changes 0-9 lines. Quick fix/merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cast values to string before b64encoding them in secrets

2 participants