Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format key in the same way as certificate #175

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

samwmarsh
Copy link

@samwmarsh samwmarsh commented Oct 30, 2023

Description

Currently only the certificate has a prefix and suffix added if it doesn’t exist. This is to bring the SAML key inline.

Motivation and Context

In #83 we’ve been having issues with SAML working when not using AAD as the identity provider. We’ve been able to get this working with values within the config.json, however we’re currently getting issues when passing in environment variables. We’re concerned that the \n in the key is causing it to be interpreted incorrectly when being passed as an env var in Helm/K8s so we’d like to add this to attempt to resolve this issue.

How Has This Been Tested?

Currently tested same logic already works for certificate. I’m unaware of the impacts, I’m new to golang and it’s quite confusing to attempt to follow so please test on my behalf!

Screenshots (if appropriate):

Types of changes

  • Chore (a change that does not modify the application functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • Documentation updates are needed, and have been made accordingly.
  • I have added and/or updated tests to cover my changes.
  • All new and existing tests passed.
  • My changes include a database migration.

@github-actions
Copy link

github-actions bot commented Oct 30, 2023

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@samwmarsh
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

@samwmarsh samwmarsh closed this Oct 30, 2023
@samwmarsh samwmarsh reopened this Oct 30, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Oct 30, 2023
@sircodemane
Copy link
Contributor

Hi @samwmarsh. To help provide context to these changes, would you mind please editing the PR to describe the changes made and include links to an issue if it is related? Thank you for the contribution!

@SpecterOps SpecterOps unlocked this conversation Oct 30, 2023
@samwmarsh
Copy link
Author

@codydbentley updated! Let me know if you need anything else

@samwmarsh
Copy link
Author

samwmarsh commented Oct 31, 2023

@codydbentley we've done some testing this morning and seen the following (which makes me sad and this PR invalid, but also raises a bug)

Test Case 1
Using the code in this PR for tls.go,
supply the SAML certificate without the BEGIN/END certificate values via the config.json file
supply the SAML key without the BEGIN/END private key values via the config.json file
error message "[panic recovery] runtime error: invalid memory address or nil pointer dereference"

Test Case 2
Using the code in the main branch for tls.go
supply the SAML certificate without BEGIN/END certificate values via the config.json file
supply the SAML key with the BEGIN/END private key values via the config.json file
SAML works

Test Case 3
Using the code in the main branch for tls.go
supply the SAML certificate without BEGIN/END certificate values via environment variable bhe_saml_sp_cert
supply the SAML key with the BEGIN/END private key values via environment variable bhe_saml_sp_key
error message "[panic recovery] runtime error: invalid memory address or nil pointer dereference"

Test cases 2 and 3 were where we were before raising this PR, with the idea that the \n character in the BEGIN PRIVATE KEY and END PRIVATE KEY lines were causing this error, however as proven with test case 1, this is not the case. In fact, the kernel panic happens in both cases 1 and 3.

As a note, this [panic recovery] references

func tryParsePrivateKey(key string) (*rsa.PrivateKey, error) {

To generate key/certificate we're just simply doing

openssl genpkey -algorithm RSA -out key.pem
openssl req -new -key -key.pem -out csr.csr
openssl x509 -req -days 365 -in csr.csr -signkey key.pem -out cert.crt

And using cert.crt as the certificate, key.pem as the key. This is confirmed working as described in Test Case 2.

@sircodemane sircodemane added the triage This issue requires triaging label Mar 15, 2024
@elikmiller elikmiller added the ticketed Ticket has been created internally for tracking label Jun 7, 2024
@StephenHinck
Copy link
Collaborator

@samwmarsh - we have some work upcoming in this area that will allow us to review and get this across the line properly. Our apologies for the delay in merging!

@sircodemane sircodemane added the external This pull request is from an external contributor label Jun 12, 2024
@urangel
Copy link
Contributor

urangel commented Aug 13, 2024

@samwmarsh Apologies for the slow review and thank you for your patience. I noticed there are new suggestions mentioned in #83, have you tried them out by chance? Specifically, this comment: #83 (comment).

The code changes in this pull request are well contained and clear though it looks like the newly added formattedKey variable is not being used anywhere so the formatting changes have no effect in the logic.

Let us know if you try the suggestions mentioned here #83 (comment) and if it works or not for you. Thank you!

@samwmarsh
Copy link
Author

Hi @urangel,
I think we ended up injecting these as k8s secrets into the json file directly in the end. I'm not sure what state it is in now, just that the previous test steps in #175 (comment) were the state at the time.

Thanks,
Sam

Copy link

@byt3n33dl3 byt3n33dl3 left a comment

Choose a reason for hiding this comment

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

Just want to see the runway -->

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external This pull request is from an external contributor ticketed Ticket has been created internally for tracking triage This issue requires triaging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants