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

Added submodule Tide OAuth. #172

Merged
merged 13 commits into from
Dec 8, 2020
Merged

Added submodule Tide OAuth. #172

merged 13 commits into from
Dec 8, 2020

Conversation

sonnykt
Copy link
Contributor

@sonnykt sonnykt commented Sep 3, 2020

On-behalf-of: @salsadigitalauorg <sonny@salsadigital.com.au>
@sonnykt sonnykt self-assigned this Sep 3, 2020
@sonnykt sonnykt marked this pull request as ready for review September 3, 2020 06:25
@sonnykt sonnykt force-pushed the feature/tide_oauth branch 2 times, most recently from fe71cbe to ccf34e4 Compare September 4, 2020 03:07
On-behalf-of: @salsadigitalauorg <sonny@salsadigital.com.au>
@anthony-malkoun
Copy link
Contributor

@sonnykt for my understanding why would we ever want to provide env variables for generating keys? Is it good enough to let them be generated every time? The main motivation here is that the AUTHENTICATED_CONTENT key has been painful to maintain (Lagoon does not handle multiline config variables correctly) and meant that it had to be added manually for PR environments (and remember to add it for new environments). If there is value to having a known value for the keys, can it be something else like the token that TFA uses or does it have to be a full RSA key?

* If the TIDE_OAUTH_ environment variables are set, the module will copy
the keys to `private://oauth.key` and `private://oauth.pub`.
* Otherwise, the module will generate a new key pair.
3. _(Optional - **Lagoon only**)_ Add a `post-rollout` task to generate the OAuth
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any reason this couldn't be an openssl command to generate on the fly from scratch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if the key changes, all existing tokens become invalid, even if they are not expired.

Copy link
Contributor

Choose a reason for hiding this comment

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

So if the deploy step checked if the key existed first before trying to create it, then it would work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@sonnykt sonnykt Oct 27, 2020

Choose a reason for hiding this comment

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

it only happens upon installation. If it's already on Prod and you launch a new dev env, the key pair doesn't exist on the new env and it still fails. There is no mechanism for Drupal to check the key pair upon init, hence the lagoon post-rollout task to trigger the Drush command copy the env to the key pair. The Drush command doesn't generate a new key pair if the env var doesn't exist.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you see any issue if we use a HMAC key rather than an RSA key @sonnykt ? It should just be the instructions that change. HMAC will be a single line token that can then be defined at the project level in Lagoon (and overridden for production) and will be able to be managed by our configuration management.

@@ -0,0 +1,12 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

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

We are still on Drush 8, does this present an issue here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's not an issue. drush.services.yml only takes effect from Drush 9. That snippet ensures that we support both 8 and 9.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@sonnykt
Copy link
Contributor Author

sonnykt commented Oct 27, 2020

@sonnykt for my understanding why would we ever want to provide env variables for generating keys? Is it good enough to let them be generated every time? The main motivation here is that the AUTHENTICATED_CONTENT key has been painful to maintain (Lagoon does not handle multiline config variables correctly) and meant that it had to be added manually for PR environments (and remember to add it for new environments). If there is value to having a known value for the keys, can it be something else like the token that TFA uses or does it have to be a full RSA key?

If there is no env variable, the module will generate a random key pair upon its installation. The env var is to ensure that all envs have the same key pair.

@anthony-malkoun
Copy link
Contributor

@sonnykt for my understanding why would we ever want to provide env variables for generating keys? Is it good enough to let them be generated every time? The main motivation here is that the AUTHENTICATED_CONTENT key has been painful to maintain (Lagoon does not handle multiline config variables correctly) and meant that it had to be added manually for PR environments (and remember to add it for new environments). If there is value to having a known value for the keys, can it be something else like the token that TFA uses or does it have to be a full RSA key?

If there is no env variable, the module will generate a random key pair upon its installation. The env var is to ensure that all envs have the same key pair.

And more importantly, if I understand correctly @sonnykt that they remain the same after deploy? See my previous comment re: using a HMAC rather than RSA. If this is ok then I'm ok with this. Maintaining the AUTHENTICATED_CONTENT key has been a complete pain which I want to avoid.

@sonnykt
Copy link
Contributor Author

sonnykt commented Oct 27, 2020

@sonnykt for my understanding why would we ever want to provide env variables for generating keys? Is it good enough to let them be generated every time? The main motivation here is that the AUTHENTICATED_CONTENT key has been painful to maintain (Lagoon does not handle multiline config variables correctly) and meant that it had to be added manually for PR environments (and remember to add it for new environments). If there is value to having a known value for the keys, can it be something else like the token that TFA uses or does it have to be a full RSA key?

If there is no env variable, the module will generate a random key pair upon its installation. The env var is to ensure that all envs have the same key pair.

And more importantly, if I understand correctly @sonnykt that they remain the same after deploy? See my previous comment re: using a HMAC rather than RSA. If this is ok then I'm ok with this. Maintaining the AUTHENTICATED_CONTENT key has been a complete pain which I want to avoid.

I don't think OAuth2 server accepts HMAC key. It requires a key pair.

@anthony-malkoun
Copy link
Contributor

Thinking some more about this @sonnykt and the install creates a valid key in public:// which will be persisted across builds. Do you see any issue with just using this initial key ongoing? Because of short comings of environment variables in Lagoon I don't think we will ever need to generate them from environment variables. Thoughts?

@sonnykt
Copy link
Contributor Author

sonnykt commented Oct 28, 2020

Thinking some more about this @sonnykt and the install creates a valid key in public:// which will be persisted across builds. Do you see any issue with just using this initial key ongoing? Because of short comings of environment variables in Lagoon I don't think we will ever need to generate them from environment variables. Thoughts?

The module installation creates a key pair in private:// (not public) and the key pair remains in the persistent storage. However, once the module is enabled on production and you later launch a new non-prod env, the module does not create a new key pair on that env because it is already installed in the database. The new env doesn't have a valid key pair. The key pair from prod is not copied to the new env, hence the module fails to work.

The post-rollout task runs the Drush command to generate the key pair from the env variables, but it doesn't generate a new key pair if the env variables are not set. We could modify that command to do:

  • check if there is a valid key pair in private://
  • if not, try to create a key pair from env variables
  • if the env variables are not set, generate a new key pair.

@anthony-malkoun
Copy link
Contributor

Thinking some more about this @sonnykt and the install creates a valid key in public:// which will be persisted across builds. Do you see any issue with just using this initial key ongoing? Because of short comings of environment variables in Lagoon I don't think we will ever need to generate them from environment variables. Thoughts?

The module installation creates a key pair in private:// (not public) and the key pair remains in the persistent storage. However, once the module is enabled on production and you later launch a new non-prod env, the module does not create a new key pair on that env because it is already installed in the database. The new env doesn't have a valid key pair. The key pair from prod is not copied to the new env, hence the module fails to work.

The post-rollout task runs the Drush command to generate the key pair from the env variables, but it doesn't generate a new key pair if the env variables are not set. We could modify that command to do:

  • check if there is a valid key pair in private://
  • if not, try to create a key pair from env variables
  • if the env variables are not set, generate a new key pair.

I think this is the best solution. That post deploy step can stay in place as it won't be destructive. Do you think it needs some sort of --refresh or --force flag that can get it to generate new key pair, ignoring what's in private://.
It would be nice if Simple OAuth supported the key module (unfortunately not https://www.drupal.org/project/simple_oauth/issues/3133698 - the issue being a short coming in the implementation of the library beneath the module thephpleague/oauth2-server#1007) but that's not an option.

@anthony-malkoun
Copy link
Contributor

The post-rollout task runs the Drush command to generate the key pair from the env variables, but it doesn't generate a new key pair if the env variables are not set. We could modify that command to do:

  • check if there is a valid key pair in private://
  • if not, try to create a key pair from env variables
  • if the env variables are not set, generate a new key pair.

Hey @sonnykt did this get done?

@sonnykt
Copy link
Contributor Author

sonnykt commented Dec 6, 2020

The post-rollout task runs the Drush command to generate the key pair from the env variables, but it doesn't generate a new key pair if the env variables are not set. We could modify that command to do:

  • check if there is a valid key pair in private://
  • if not, try to create a key pair from env variables
  • if the env variables are not set, generate a new key pair.

Hey @sonnykt did this get done?

@anthony-malkoun I doubt that. IIRC we only discussed but haven't got a final decision yet.

@anthony-malkoun
Copy link
Contributor

The post-rollout task runs the Drush command to generate the key pair from the env variables, but it doesn't generate a new key pair if the env variables are not set. We could modify that command to do:

  • check if there is a valid key pair in private://
  • if not, try to create a key pair from env variables
  • if the env variables are not set, generate a new key pair.

Hey @sonnykt did this get done?

@anthony-malkoun I doubt that. IIRC we only discussed but haven't got a final decision yet.

Who are you waiting for a final decision from? I'm happy for this to happen.

@sonnykt
Copy link
Contributor Author

sonnykt commented Dec 7, 2020

@anthony-malkoun you'd probably get @vincent-gao to make the change as my allocation this week is for VT.

…keys. (#197)

* [tide_oauth_changes] Updated drush command to generate keys if no envkeys.
@MdNadimHossain MdNadimHossain merged commit e091b57 into develop Dec 8, 2020
@MdNadimHossain MdNadimHossain deleted the feature/tide_oauth branch December 8, 2020 04:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants