GitLab Geo: OAuth Authentication
Rationale
Current implementation requires Geo (#76) to share Redis connection between primary and secondary nodes, in order to make authentication possible.
We can't authenticate directly to the secondary nodes because Devise must save state data to the Database for modules like:
- Recoverable
- Registerable (we don't need it on a secondary node)
- Rememberable
- Trackable
- Lockable
Disabling some of them may have security consequences. In the future if we decide being able to authenticate on a secondary is a requirement, we will have to patch Devise and store state data in another datastore (like Redis), or implement a more sophisticated master <-> master replication topology.
OAuth Authentication
OAuth authentication is the most obvious way to implement a remote login protocol and share authentication status in the context of a user session.
GitLab already supports acting as an OAuth Identity Provider (we use DoorKeeper for that).
The idea is to create automatically an OAuth Application (see /admin/applications
), and link it to a secondary Geo Node.
Authentication Workflow
When user wants to login, it will redirect to OAuth Identity Provider (primary Geo node), and will add to the state param, the return_to url, in the same way GitLab CI did.
User will connect to the primary node using any type of authentication defined there.
On first access he/she will be redirected to the OAuth authorization screen (where he/she must "Allow" the application).
After the first access, it will be transparent and automatically redirected to the secondary node.
Checklist
- When a secondary Geo node is created an OAuth Application is created associated to it
- When a secondary Geo node is removed the associated OAuth application is also removed
- When a user tries to login it must be redirected to the primary node using the OAuth workflow
- The user must be redirected to the "first accessed url before authentication" (as expected)
- User should be able to logout from a secondary node
- It displays authentication errors when OAuth application is not present
- It handles authentication errors when OAuth flow fails
- Solution for what to do when/if OAuth application is removed