Skip to content

Commit

Permalink
Add audit log (#59)
Browse files Browse the repository at this point in the history
<!--- 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": "[email protected]"
        },
        "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.
  • Loading branch information
sailinder authored Dec 20, 2024
2 parents 9ce484b + 2f165d5 commit a9ac8d5
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions pkg/pics/audit/audit_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,31 @@ func NewAuditClient(opts *ClientOpts) (*Client, error) {
}

func (c *Client) CreateSuccessfulLoginAuditEntry(ss *sessions.SessionState, appURL string, tenantID string) {
c.createAuditEntry(ss, appURL, tenantID, "0", "Success")
coding := Coding{
System: "http://hl7.org/fhir/ValueSet/audit-event-type", Version: "1", Code: "110114", Display: "User Authentication", UserSelected: ""}
c.createAuditEntry(ss, appURL, tenantID, "0", "Success", &coding)
}

func (c *Client) CreateFailedLoginAuditEntry(ss *sessions.SessionState, appURL string, tenantID string, errorDesc string) {
c.createAuditEntry(ss, appURL, tenantID, "1", errorDesc)
coding := Coding{
System: "http://hl7.org/fhir/ValueSet/audit-event-type", Version: "1", Code: "110114", Display: "User Authentication", UserSelected: ""}
c.createAuditEntry(ss, appURL, tenantID, "1", errorDesc, &coding)
}

func (c *Client) createAuditEntry(ss *sessions.SessionState, appURL string, tenantID string, outcomeCode string, outcomeDesc string) {
func (c *Client) CreateSuccessfulLogoutAuditEntry(ss *sessions.SessionState, appURL string, tenantID string) {
coding := Coding{
System: "http://hl7.org/fhir/ValueSet/audit-event-type", Version: "1", Code: "110123", Display: "Logout", UserSelected: "All Sessions"}
c.createAuditEntry(ss, appURL, tenantID, "0", "Success", &coding)
}
func (c *Client) createAuditEntry(ss *sessions.SessionState, appURL string, tenantID string, outcomeCode string, outcomeDesc string, coding *Coding) {
if !c.enabled {
return
}
auditObject := RootEvent{
ResourceType: "AuditEvent",
Event: &Event{
Type: &Coding{
System: "http://hl7.org/fhir/ValueSet/audit-event-type", Version: "1", Code: "110114", Display: "User Authentication"},
coding.System, coding.Version, coding.Code, coding.Display, coding.UserSelected},
Action: "E",
DateTime: time.Now().UTC().Format(time.RFC3339),
Outcome: outcomeCode,
Expand Down

0 comments on commit a9ac8d5

Please sign in to comment.