Closed Schnitzel closed 2 years ago
Possible solution:
Deployment post-rollout
(drush sql-sync @production @self
):
oc -n drupal-example-master exec cli-21-l4vqk -i -t -- sh -c "export LAGOON_REFRESH_TOKEN=TEEST7; sh"
LAGOON_TOKEN
environment, authenticates at Remote Shell SSH via existing SSH Key (that only has guest role account) and passes LAGOON_TOKEN
to remote shell system of Lagoon (via SSH environment variable forwarding SendEnv
). Lagoon Remote Shell System uses provided LAGOON_TOKEN
and not the one generated from the SSH public key to check if user (aka build system) has access to production enviornment.Locally drush sql-sync
with user having developer role:
LAGOON_TOKEN
, does not find one, does also not find LAGOON_REFRESH_TOKEN
therefore falls back to create LAGOON_TOKEN
via SSH (https://github.com/amazeeio/lagoon/blob/master/services/drush-alias/web/aliases.drushrc.php.stub#L178)LAGOON_TOKEN
environment variable.LAGOON_TOKEN
environment, authenticates at Remote Shell SSH via existing SSH Key (that has permissions of the current user = developer role) and passes LAGOON_TOKEN
to remote shell system of Lagoon (via SSH environment variable forwarding SendEnv
). Lagoon Remote Shell System uses provided LAGOON_TOKEN
and not the one generated from the SSH public key to check if user (aka build system) has access to production enviornment (which will be denied).Lagoon Drush SQL-Sync Tasks:
LAGOON_REFRESH_TOKEN
into task podLAGOON_TOKEN
environment, authenticates at Remote Shell SSH via existing SSH Key (that only has guest role account) and passes LAGOON_TOKEN
to remote shell system of Lagoon (via SSH environment variable forwarding SendEnv
). Lagoon Remote Shell System uses provided LAGOON_TOKEN
and not the one generated from the SSH public key to check if user (aka build system) has access to production enviornment.Lagoon SQL-Dump Tasks:
LAGOON_REFRESH_TOKEN
into task poddrush sql-dump
has finishedgetLagoonAccessToken.sh
to generate access token from LAGOON_REFRESH_TOKEN
LAGOON_TOKEN
(this means we can remove the permission to upload files for guests)getLagoonAccessToken.sh
script and provide it into /lagoon/getLagoonAccessToken.sh
inside commons
ImagegetLagoonAccessToken.sh
if there is a refresh token existing before running ssh: https://github.com/amazeeio/lagoon/blob/master/services/drush-alias/web/aliases.drushrc.php.stub#L178exec
exec
This is now possible - all branches have a maintainer token, so can access other branches
With Lagoon 1.0.0 and RBAC all post-rollout tasks and also all remote connections tasks are running under a user that has
guest
Role. Thisguest
does not have permissions to use the remote shell and therefore runningdrush sql-sync
within a post-rollout task or inside a remote shell connection will fail.This problem also existed for Lagoon Tasks, but we solved this with injecting a maintainer token into the Task Pod: https://github.com/amazeeio/lagoon/issues/1229
For problem here there are multiple possible solutions:
give the remote shell connection a role that can use remote shell connections (like
maintainer
or create a new role all together). While this solves the underlining problem and has been tested already it would allow a user with no access to the production environment allow to elevate it's own priviledges with connecting into the development environment and "steal" the SSH key of the default user which has this additional. Therefore allowing developers without production environment access to access such enviornment.Abandoning running of
drush sql-sync
during a post-rollout task all together and instead write a small bash script which creates a lagoon task for runningdrush-sql sync
inside that task and then within the bash script to wait until that lagoon task has been finished. This technically would work but brings it's own challenges:drush sql-sync
inside post-rollout will fail.Abandoning running of
drush sql-sync
during a post-rollout task all together and allow to trigger Lagoon Tasks via.lagoon.yml
post rollout tasks. The Post Rollout Tasks yaml scheme is already prepared to run other type of tasks thanrun
. We could there directly do something like:Which then automatically creates a Lagoon Task, waits until that lagoon task is done and continues with the deployment. While this is probably much easier to use than running a BashScript in Solution 2, there are still downsides:
drush sql-sync
inside post-rollout will fail.which runs the task only if the defined script does not fail
during any remote shell connection we could inject the Lagoon JWT of the user that currently is connecting to the remote shell into the destination of the connection (like the 'cli' container). This would technically remove the need to inject an SSH key into the CLI container all together. There are only a couple of issues to solve:
oc rsh
would not have a JWT at all, as they are not connecting via the lagoon remote shell system and therefore no JWT token would be generated. (this probably speaks to the fact to keep the ssh key with the default-user).I personally think Nr. 4 is the best solution we could do right now, as it makes the most sense to have the same JWT running inside a remote shell as the user that connects to it (basically mimiks the SSH Agent system).