Skip to content

Conversation

lucasgameiroborges
Copy link

@lucasgameiroborges lucasgameiroborges commented Apr 8, 2024

Issue

#431

Solution

Considering this is an error that can be solved by human action directly on the live charm, I chose the following approach: If the 403 Unauthorized error is catched, the charm enters Blocked status with specific message and a helpful explanation about the problem is written in the logs:

juju status:

Unit                         Workload  Agent      Address       Ports  Message
untrusted-postgresql-k8s/0*  blocked   executing  10.1.110.75          Insufficient permissions, try: `juju trust untrusted-postgresql-k8s --scope=cluster`

juju logs:

unit-postgresql-k8s-0: 22:26:23 INFO juju.worker.uniter.operation ran "leader-elected" hook (via hook dispatching script: dispatch)
unit-untrusted-postgresql-k8s-1: 13:24:43 ERROR unit.untrusted-postgresql-k8s/1.juju-log
            Access to k8s cluster resources is not authorized. This happens when RBAC is enabled and the deployed application was not trusted by the juju admin.
            To fix this issue, run `juju trust untrusted-postgresql-k8s --scope=cluster` (or remove & re-deploy untrusted-postgresql-k8s with `--trust`)

@dragomirp
Copy link
Contributor

We should add integration test that the charm will block and unblock correctly.

@lucasgameiroborges
Copy link
Author

lucasgameiroborges commented Apr 11, 2024

Added a small set of integration tests for the feature. Due to RBAC not being enabled by default in our reusable workflows, I had to use sub-processes to interact with microk8s directly, as well as re-establish model connection after microk8s restart. Running the test multiple times locally and in CI without fails, it looks stable.

About the OSError: [Errno 9] Bad file descriptor error messages, I'm still not quite sure what triggers them (probably a consequence of microk8s interference), but they don't affect the test behavior in any way, besides spamming the CI logs. The evolution of the model state works as expected.

Copy link
Member

@marceloneppel marceloneppel left a comment

Choose a reason for hiding this comment

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

It looks great! Thanks @lucasgameiroborges!

I left only one comment.

Copy link
Contributor

@taurus-forever taurus-forever left a comment

Choose a reason for hiding this comment

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

Nice! Thank you!

@lucasgameiroborges lucasgameiroborges merged commit 9e4c16c into main Apr 12, 2024
@lucasgameiroborges lucasgameiroborges deleted the lucas/dpe-3885 branch April 12, 2024 11:58
BON4 pushed a commit to BON4/postgresql-k8s-operator that referenced this pull request May 20, 2024
…-trust` flag (canonical#440)

* improve error message for trust flag

* fix message text

* fix docstring

* fix explanation

* add integration test for new trust behavior

* test different app name for deploy

* fix bug

* enable rbac from inside test

* fix typo

* use sudo with microk8s enable

* remove check true

* fix linting

* test subprocess call

* remove fast-forward

* test connectivity and enable rbac

* fix integration test + update endpoints

* revert poetry lock change

* reposition endpoint update in event

* reposition cleanup resource call
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.

4 participants