Repository navigation
Conversation
|
A very helpful confirmation from @jspiro on the #804 has confirmed that the reference to
I am now confident that new-line decoding is the issue and that this is the appropriate fix. |
|
@jcudit Could this make it into 4.18? |
kfcampbell
left a comment
There was a problem hiding this comment.
I had a couple comments...do you mind helping me understand these changes a little better?
|
|
||
| if v, ok := appAuthAttr["pem_file"].(string); ok && v != "" { | ||
| appPemFile = v | ||
| appPemFile = strings.Replace(v, `\n`, "\n", -1) |
There was a problem hiding this comment.
Do you think it's worth writing a comment here to explain this behavior? I think it's not super obvious and probably worth documenting in some manner.
There was a problem hiding this comment.
I have added a comment to the code with some context.
I chose to add new line replacement in the provider's configuration code because it felt most appropriate as it is dealing with how the provider is configured, however, it could be more clear if the behaviour was added to the part of the provider where the PEM is consumed, i.e: https://github.com/integrations/terraform-provider-github/blob/main/github/apps.go#L19
func GenerateOAuthTokenFromApp(baseURL, appID, appInstallationID, pemData string) (string, error) {
+ pemData = strings.Replace(pemData, `\n`, "\n", -1)
appJWT, err := generateAppJWT(appID, time.Now(), []byte(pemData))Personally I think it belongs in the configuration code but I am happy to move it into the consuming code (either apps.go@GenerateOAuthTokenFromApp or apps.go@generateAppJWT) if you think that will be clearer about the behaviour and intent -- let me know if you do and I'll make the change!
There was a problem hiding this comment.
Thanks for doing that! I agree with you that this change belongs at the configuration level, so all consumers can trust they have the correctly-escaped version of the certificate.
I was a little concerned that this might break existing certiricate handling somehow, but I believe that the base64-encoded nature of the certificates guarantees that there won't be \n string literals in the cert that we accidentally over-replace, so I think this is pretty safe.
kfcampbell
left a comment
There was a problem hiding this comment.
My approval doesn't grant anything to this PR, but FWIW @jcudit I think this can be merged.
|
|
||
| if v, ok := appAuthAttr["pem_file"].(string); ok && v != "" { | ||
| appPemFile = v | ||
| appPemFile = strings.Replace(v, `\n`, "\n", -1) |
There was a problem hiding this comment.
Thanks for doing that! I agree with you that this change belongs at the configuration level, so all consumers can trust they have the correctly-escaped version of the certificate.
I was a little concerned that this might break existing certiricate handling somehow, but I believe that the base64-encoded nature of the certificates guarantees that there won't be \n string literals in the cert that we accidentally over-replace, so I think this is pretty safe.
* fix: Replace `\n` strings with new lines in pem_file * chore: Format imports using alphabetical ordering * docs: Describe replacement of `\n` with new lines in PEM file * style: Remove erroneous trailing whitespace
#804 added environment variable input for
pem_filebut golang's pem decode functionality only works when the string contains actual new lines. Terraform Cloud does not permit new lines in Environment Variables, therefore it is currently not possible to use theGITHUB_APP_PEM_FILEEnvironment Variable on Terraform Cloud.Unfortunately, there's no test coverage for the functionality in question so while this is, in principle, a very simple change, I'm not entirely sure if there are side effects I have not considered.
https://play.golang.org/p/h3Pn97nqF8j