Commit Graph

2497 Commits

Author SHA1 Message Date
Eduardo Vozniak b5c83e6649
Flush all sessions in logout all (#68)
## Description

During logout all sessions, the session should be removed from Redis,
otherwise even though the token is expired (cannot write), the user can
still read data in the application while the session (15 minutes of
refresh token) is still valid
for that we are mapping all session keys to a new entry (encrypted) in
Redis based on user information and the secret
after logout all sessions, we remove the current session from Redis
(already existing mechanism), and also read this entry to remove all
other active sessions


![image](https://github.com/user-attachments/assets/a8e26dbc-79df-4a12-a87d-44b66cc1e577)


## Motivation and Context

AB#1625768

## How Has This Been Tested?

Locally with pics

## Checklist:

- [ ] My change requires a change to the documentation or CHANGELOG.
- [ ] I have updated the documentation/CHANGELOG accordingly.
- [x] I have created a feature (non-master) branch for my PR.
2025-06-11 10:01:59 -03:00
Felipe Fey 5b027c7c78
fixing lint and tests 2025-06-11 08:28:43 -03:00
Felipe Fey 02c755edd0
unit tests 2025-06-11 07:09:14 -03:00
Felipe Fey c898672fcb
renaming clear all, removing panik 2025-06-09 14:07:00 -03:00
Felipe Fey c454e8d4d9
Flush al sessions in logout all 2025-06-09 11:14:21 -03:00
Anderson Valério 5a1d721a60
Fix revoke access token error handling (#67)
- [x] Do not stop flow if revoke fails. 
- [x] Properly handle/log error

## Motivation and Context

<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->

## How Has This Been Tested?

<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->

## Checklist:

<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->

- [ ] My change requires a change to the documentation or CHANGELOG.
- [ ] I have updated the documentation/CHANGELOG accordingly.
- [ ] I have created a feature (non-master) branch for my PR.
2025-06-02 16:58:00 -03:00
Anderson Valério ce5990487c
Merge branch 'anderson/fix-revoke-error' of https://github.com/philips-forks/oauth2-proxy into anderson/fix-revoke-error 2025-06-02 14:58:53 -03:00
Anderson Valério f065966ec5
fix typo 2025-06-02 14:56:07 -03:00
Anderson Valério f6f1f4353c
Update pics_oauthproxy.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-06-02 14:55:00 -03:00
Anderson Valério 58389a741a
t 2025-06-02 14:42:57 -03:00
Anderson Valério 59127d43b7
t 2025-06-02 14:42:50 -03:00
Anderson Valério 7a2b1f8c19
fix error 2025-06-02 14:40:10 -03:00
Anderson Valério b5da4ecc31
Revoke access token on logout (#66)
Adding functionality to revoke access token on logout. This will use the
newly added OAUTH2_PROXY_BACKEND_REVOKE_ACCESS_TOKEN_URL environment
variable.

AB#1624642

## Motivation and Context

Adding the functionality to revoke an access token on logout prevents an
attacker from continuing to use a stolen access token until the
expiration of the TTL.

## How Has This Been Tested?

Running it locally integrated with Pics.
2025-05-09 06:51:10 -03:00
Anderson Valério c922ebecb0
fix audit log 2025-05-09 06:05:01 -03:00
Anderson Valério 5e57984cb1
try to remove linter change 2025-05-09 06:00:11 -03:00
Anderson Valério 67e218c6b4
try to remove linter change 2025-05-09 05:57:22 -03:00
Anderson Valério 2e210d1cfd
fix linter 2025-05-07 09:36:44 -03:00
Anderson Valério 1c4797a034
fix lint 2025-05-07 09:22:38 -03:00
Anderson Valério 64be9956ed
anderson/fix golint 2025-05-07 09:17:35 -03:00
Anderson Valério 7ad27949b2
remove deprecated option 2025-05-07 08:43:01 -03:00
Anderson Valério 13549c6092
update docs 2025-05-07 08:17:17 -03:00
Anderson Valério 1102ad256c
revoke access token on logout 2025-05-07 08:09:50 -03:00
Anderson Valério b3bf233e57
Fix audit log for logout all (#65)
- [x] Fix audit for logout all

AB#1579962
2025-01-14 16:07:15 -03:00
Anderson Valério bd198f3dc4
fix audit 2025-01-14 15:59:05 -03:00
Sailinder Harpal 2b0118c1f0
Move audit log before ending session (#64)
<!--- Provide a general summary of your changes in the Title above -->

## Description

Change the audit code from 110123 to 110114.

## Motivation and Context

The code 110123 was not present and know by the audit log server.
after running `cf logs oauth_proxy --recent` in the
pics_client_test_us_east we saw this error:
`2025-01-14T11:06:04.64+0100 [APP/PROC/WEB/0] ERR 2025/01/14 10:06:04
Not able to send the audit message
{"issue":[{"severity":"error","code":"invalid","details":{"coding":[{"system":"https://www.hl7.org/fhir/valueset-operation-outcome.html","code":"MSG_ERROR_PARSING"}],"text":"Not
complaint with AuditEvent specification"},"diagnostics":"Not complaint
with AuditEvent specification"}],"resourceType":"OperationOutcome"}`

Unfortunately there is no error message logged in Kibana.

## How Has This Been Tested?

<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->

## Checklist:

<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->

- [ ] My change requires a change to the documentation or CHANGELOG.
- [ ] I have updated the documentation/CHANGELOG accordingly.
- [ ] I have created a feature (non-master) branch for my PR.
2025-01-14 15:59:30 +01:00
Harpal, Sailinder c589d205ac
revert code 2025-01-14 15:51:19 +01:00
Harpal, Sailinder acd05b771d
use existing code for user authentication 2025-01-14 15:43:41 +01:00
Harpal, Sailinder 1e80995c7d
Call audit log before ending calling all sessions 2025-01-14 14:59:28 +01:00
Anderson Valério 1a4f3cae73
Add audit log to logout all sessions (#62)
## Description

- [x] Adding audit log to logout all sessions
- [x] Updating variable name 

AB#1437807

## Motivation and Context

Audit log for logout all sessions

## How Has This Been Tested?

Locally integrated with PICS. Used webhook to receive the audit entry.

## Checklist:

<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->

- [x] My change requires a change to the documentation or CHANGELOG.
- [x] I have updated the documentation/CHANGELOG accordingly.
- [x] I have created a feature (non-master) branch for my PR.
2025-01-08 11:08:51 -03:00
Anderson Valério b50dc018f2
add auditlog 2024-12-30 15:02:53 -03:00
Anderson Valério a31eabc52d
Merge branch 'pics' into anderson/add-audit-log-logoutall 2024-12-30 14:38:58 -03:00
Anderson Valério 7f91759342
update variable name 2024-12-30 14:38:29 -03:00
Joana Deluca Kleis 673256fd30
fix: fix log message params (#61)
## Description

Small fix in the oidc cookie refresh log message (the params were
inverted).
2024-12-30 13:50:27 -03:00
Joana Deluca Kleis 2f4b00f577
fix: fix log message params 2024-12-30 13:36:54 -03:00
Anderson Valério 48f13a7004
feat: sign out all sessions (#60)
## Description

Adding support for `/sign_out_all_sessions`.

/sign_out_all_sessions endpoint will remove the current session and make
a POST request to IAM, configured via
`OAUTH2_PROXY_BACKEND_LOGOUT_ALL_SESSIONS_URL` env, to invalidate all
the tokens and sessions. This will not invalidate other user sessions.

Once the tokens and sessions are invalidated, after the refresh token
period defined on the `OAUTH2_PROXY_COOKIE_REFRESH` env, OAuth will fail
to refresh the access token and clear that session.

related to:
- https://github.com/philips-internal/pics-foundation-envoy/pull/105
- https://github.com/philips-internal/pics/pull/3006


[AB#1579962](https://tfsemea1.ta.philips.com/tfs/TPC_Region11/0839b845-d626-4499-94ae-563a86a88d0a/_workitems/edit/1579962)

## Motivation and Context

Possibility for signing out on all devices.

## How Has This Been Tested?

Integrated locally with PICS by running binary. Docs
[here](https://github.com/philips-internal/pics/blob/main/src/services/Oauth2Proxy/docs/development.md).

## Checklist:

- [x] Add OAUTH2_PROXY_BACKEND_LOGOUT_ALL_SESSIONS_URL env
- [x] Add  /sign_out_all_sessions endpoint
- [x] Remove other user sessions when tokens are invalid
2024-12-30 08:43:50 -03:00
Anderson Valério 982e27fc00
tests for pics_oauthproxy 2024-12-27 14:59:07 -03:00
Anderson Valério f46f7a39f3
update test for refresh token change 2024-12-27 12:02:26 -03:00
Anderson Valério 72f89818fa
add doc for new env 2024-12-27 10:19:59 -03:00
Anderson Valério 92e7960b6c
fix lint bodyclose 2024-12-27 10:10:38 -03:00
Anderson Valério 8bf8b0ecc2
fix userID lint 2024-12-27 09:57:35 -03:00
Anderson Valério 1da13b0eff
fix userID lint 2024-12-27 09:50:43 -03:00
Anderson Valério 6cf267d368
clear session when refresh token fail to generate a new acess token 2024-12-27 08:38:23 -03:00
Anderson Valério 2851483446
add sign_out_all_sessions endpoint 2024-12-27 08:38:10 -03:00
Anderson Valério fb64fad321
add BackendLogoutAllSessionsURL configuration 2024-12-27 08:37:43 -03:00
Sailinder Harpal a9ac8d5496
Add audit log (#59)
<!--- Provide a general summary of your changes in the Title above -->

## Description

<!--- Describe your changes in detail -->
For Story AB#1618387

Adding function to audit log 'logout for all session'.

Reference documentation:
https://hl7.org/fhir/valueset-audit-event-type.html
https://hl7.org/fhir/R4/codesystem-dicom-dcim.html#dicom-dcim-110114

## Motivation and Context

<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->

## How Has This Been Tested?

Tested locally with webhook.

Build a new docker image in wsl with `docker buildx build -t
oauth-local:v0.0.3 .`
Update the docker-compose.yml file to 
Updated the environment variable for .env.oauth2-proxy.us-east
Adding =>
`OAUTH2_PROXY_AUDIT_URL=https://webhook.site/0d7939ba-13f3-4cbc-ac2c-b814a3add0ca`

The audit logging is posted to the webhook =>
`
{
    "resourceType": "AuditEvent",
    "event": {
        "type": {
            "system": "http://hl7.org/fhir/ValueSet/audit-event-type",
            "version": "1",
            "code": "110123",
            "display": "Logout",
            "userSelected": "All Sessions"
        },
        "action": "E",
        "dateTime": "2024-12-19T12:44:30Z",
        "outcome": "0",
        "outcomeDesc": "Success"
    },
    "participant": [
        {
            "userId": {
                "value": "SECRET"
            },
            "altId": "SECRET",
            "requestor": true
        }
    ],
    "source": {
        "identifier": {
            "type": {
"system": "http://hl7.org/fhir/ValueSet/audit-source-type",
                "code": "4",
                "display": "Application Server"
            },
            "value": "admin_fthv@philips.com"
        },
        "type": [
            {
                "system": "http://hl7.org/fhir/security-source-type",
                "code": "1",
                "display": "End-user display device, diagnostic device."
            }
        ],
        "extension": [
            {
                "url": "/worklist",
                "extension": [
                    {
                        "url": "applicationName",
                        "valueString": "ReportingTest"
                    },
                    {
                        "url": "applicationVersion",
                        "valueString": "1"
                    },
                    {
                        "url": "serverName",
                        "valueString": "oauth2proxy"
                    },
                    {
                        "url": "componentName",
                        "valueString": "oauth2proxy"
                    },
                    {
                        "url": "productKey",
                        "valueString": "SECRET"
                    },
                    {
                        "url": "tenant",
                        "valueString": "SECRET"
                    }
                ]
            }
        ]
    }
}
`
## Checklist:

<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->

- [ ] My change requires a change to the documentation or CHANGELOG.
- [ ] I have updated the documentation/CHANGELOG accordingly.
- [ ] I have created a feature (non-master) branch for my PR.
- [ ] I have written tests for my code changes.
2024-12-20 13:05:34 +01:00
Harpal, Sailinder 2f165d5eab
Change text 2024-12-19 15:52:54 +01:00
Harpal, Sailinder b1bfa56d0e
Add audit log 2024-12-19 14:31:01 +01:00
Anderson Valério 9ce484ba03
Merge 7.7.1 (#58)
## Description

Merge from Upstream/Release/7.7.1

AB#1611455

## Motivation and Context

Keeping OAuth2-Proxy up-to-date with the upstream

## How Has This Been Tested?

Created a local container image of the oauth-proxy from this PR and
integrated it with Reporting locally.
- run in the root of this repo
  - docker buildx build -t oauth-local .
- Updated FROM statement in pics/src/services/Oauth2Proxy/Dockerfile to 
  - FROM oauth-local

The following flows were checked:
- Login
- Audit logs
- Logout 


## Checklist:

- [x] Merge from Upstream/Release/7.7.1
2024-12-11 08:42:13 -03:00
Anderson Valério f321907ee7
update lint in pics/audit 2024-12-09 22:09:52 -03:00
Anderson Valério 67b8fd0061
bump golanci-lint 2024-12-09 22:00:53 -03:00