
AAP 2.6-8 Containerized, Time Zone breaks get_service_token()
So for the past three weeks I've gone through the guide here, Upgrading and Migrating from AAP 2.5 RPM to 2.6 Container and wanted to document a bug I hit and I resolved it.
I'm going to fast-forward and not touch on every little tid bit during this process, but please ask questions if you want. I also do not claim 100% accuracy on the statements I make below.. this is just what I found, and what worked for me.
So went through the guide and got the the past where it's time to install 2.6 and upgrade the containerized 2.5 hosts. I've gotta mention how the installation process took upwards of 8 hours (!!!), this is on M6i.xlarge EC2's as well!
Anyway, so the installation was completing however the web gui reported an Error connecting to the Controller API. Web dev tools showed an HTTP 401 to /api/controller/v2/me/. So I started digging into the controller and gateway logs. This is a gist of what I found:
- Envoy auths theuser, add a JWT then forwards to the controller
- Controller validates the JWT, then needs the user claims from the gateway
- Controller generates a service token using datetime.now(), which in this case returned CDT or 5 hours behind UTC
- PyJWT encoded the CDT time as UTC
- Controller sends the expired token value to the gateway's /api/gateway/v1/jwt_claims/ endpoint
- Gateway rejects the expired token, returns HTTP 401
- Controller can't validate the user, returns HTTP 401 to the browser
- Dashboard shows "Error connecting to the controller api"
Now at the time I was unaware that containers default to UTC time.. I did find a RH KB on resolving the receptor images TZ, but I did not find info on the other containers. Now since I like seeing logs and events in my local timezone, I used those steps and created a mounts.conf under .config/container/ for the AAP user on all 8 hosts to set it to 'America/Chicago'.
Now this did not resolve the token issue.. I figure because Django doesn't care what the OS is set to use. So I changed the time_zone in my inventory file to 'UTC'.. went ahead and tested this by editing the /home/aap_user/aap/controller/etc/settings.py under controller_extra_settings time_zone to UTC and restarted the containers.
Controller API error resolved.
From what I gather, this might not be a problem if get_service_token() at /var/lib/awx/venv/awx/lib64/python3.12/site-packages/ansible_base/resource_registry/resource_server.py line:
payload["exp"] = datetime.now() + timedelta(seconds=expiration)
Was changed to:
from datetime import timezone
payload["exp"] = datetime.now(tz=timezone.utc) + timedelta(seconds=expiration)
But Im no python dev so.. IDK. Anyway thanks for reading.