Skip to content

Commit ce8f11a

Browse files
committed
Refactor audit log documentation to enhance clarity on viewing, exporting, and accessing logs via API
1 parent 0031238 commit ce8f11a

File tree

2 files changed

+70
-148
lines changed

2 files changed

+70
-148
lines changed

learn-pr/github/manage-sensitive-data-security-policies/includes/2-set-security-policies.md

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -147,91 +147,3 @@ Organization policies and enterprise policies set governance, access, and workfl
147147

148148
Any enterprise-level policy in “Your enterprises > Policies > Repository policies” overrides org-level settings under Settings > Member privileges.
149149

150-
## GitHub Audit Log APIs
151-
152-
Use REST or GraphQL to investigate missing assets and monitor security events.
153-
154-
### Steps to Investigate Missing Assets
155-
1. Identify the asset (e.g., repo, team, member).
156-
2. Query the audit log API (`repository.deleted`, etc.).
157-
3. Filter by event type.
158-
4. Review metadata for actor and timestamp.
159-
5. Take corrective actions.
160-
161-
**Example REST request:**
162-
```http
163-
GET /orgs/{org}/audit-log?phrase=repository.deleted
164-
Authorization: Bearer YOUR-TOKEN
165-
```
166-
167-
**Example GraphQL query:**
168-
```graphql
169-
query {
170-
auditLogEntries(first: 10, query: "repository.deleted") {
171-
nodes {
172-
action
173-
actor { login }
174-
createdAt
175-
}
176-
}
177-
}
178-
```
179-
180-
### Use Cases for Audit Logs
181-
- Investigate security incidents.
182-
- Monitor compliance.
183-
- Track changes to repos, users, and settings.
184-
- Detect unauthorized access.
185-
186-
### Audit Log Streaming
187-
Stream logs to SIEM tools (Splunk, Datadog) or storage (AWS S3, Azure Event Hubs) for real-time monitoring and long-term retention.
188-
189-
### Git and API Activity Logs
190-
Monitoring Git and API activity logs is crucial for maintaining the security and integrity of your repositories. These logs provide visibility into user actions, enabling you to detect unauthorized access, investigate incidents, and ensure compliance with organizational policies.
191-
192-
- **Git activity:** `git.push`, `pull_request`, etc.
193-
- **API activity:** `api.request`, include source IP for threat detection.
194-
195-
### Additional Events (EMUs)
196-
Enterprise Managed Users add events like `user.login`, `repository.permissions_updated`, `repository.forked`.
197-
198-
### Filtering by Token
199-
Query `?phrase=token` to find token-related actions and detect misuse.
200-
201-
## Key Security Features of a GitHub Repository
202-
- **SECURITY.md:** Define reporting and supported versions.
203-
- **Branch Protection:** Enforce reviews, status checks, and commit signing.
204-
- **Dependabot Alerts:** Automatic vulnerability detection and updates.
205-
- **Code Scanning:** Continuous analysis via CodeQL.
206-
- **Secret Scanning & Push Protection:** Real-time prevention and alerts.
207-
- **Security Advisories:** Draft, collaborate, and publish advisories.
208-
- **Dependency Graph:** Visualize and audit dependencies.
209-
- **2FA & RBAC:** Enforce strong authentication and least privilege.
210-
- **Audit Logs:** Monitor, filter, and export logs for compliance.
211-
212-
## API Access and Integrations
213-
| **Token Type** | **Description** |
214-
|----------------------------|---------------------------|
215-
| **Personal Access Tokens (PATs)** | Tokens tied to a user account for API access. |
216-
| **Installation Tokens** | Tokens generated for GitHub Apps installations with fine-grained permissions. |
217-
| **OAuth Tokens** | Tokens used for OAuth app authentication and API access. |
218-
| **Device Tokens** | Tokens used for device-based authentication flows. |
219-
| **Refresh Tokens** | Tokens used to renew expired access tokens without re-authentication. |
220-
221-
| **Rate Limit Type** | **Limit** |
222-
|--------------------------|---------------------|
223-
| **Unauthenticated** | 60 requests per hour. |
224-
| **Authenticated** | 5000 requests per hour. |
225-
| **Apps** | Varies by installation, depending on the app's configuration.|
226-
227-
**Check via API:**
228-
```sh
229-
curl -H "Authorization: token YOUR_TOKEN" \
230-
-H "Accept: application/vnd.github.v3+json" \
231-
https://api.github.com/rate_limit
232-
```
233-
234-
GitHub Apps offer fine-grained permissions and are ideal for organizational integrations, while Personal Access Tokens (PATs) are simpler and tied to user accounts, making them suitable for basic scripts but with less control. OAuth Apps should be granted the least privilege scopes, with event subscriptions managed and reviewed regularly. Organizations can restrict untrusted apps through settings to enhance security.
235-
236-
Enterprise Managed Users (EMUs) provide managed accounts with limited scope, ensuring compliance and control. Data residency policies help organizations store logs and data in specified regions, aligning with regulatory requirements. API usage should adhere to organizational policies and residency guidelines to maintain compliance.
237-

learn-pr/github/manage-sensitive-data-security-policies/includes/4-report-log.md

Lines changed: 70 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Your organization’s audit log records actions taken by organization members. A
1818
> [!NOTE]
1919
> Logs are retained for up to 90 days in GitHub Enterprise Cloud (120 days via GraphQL on Enterprise Server).
2020
21-
## Viewing Audit Logs in the GitHub UI
21+
## Viewing and Exporting Audit Logs via the GitHub UI
2222

2323
1. On GitHub.com, navigate to your organization’s **Settings > Audit log**.
2424
2. Use the **Filters** field to narrow results by qualifier (actor, repo, action, date).
@@ -35,15 +35,24 @@ Your organization’s audit log records actions taken by organization members. A
3535
| `repo` | octo-org/documentation |
3636
| `created` | 2019-06-01 |
3737

38-
## Accessing Audit Logs via APIs
38+
## Accessing Audit Logs via API
39+
40+
### REST API
41+
42+
- **Scope:** Enterprise Cloud (up to 90 days; Git events for 7 days).
43+
- **Monitors:** Settings changes, permission updates, team membership, application changes, plus Git events (push, pull, merge).
44+
45+
```http
46+
GET /orgs/{org}/audit-log?phrase=git.push
47+
Authorization: Bearer YOUR_TOKEN
48+
```
3949

4050
### GraphQL API
4151

4252
- **Scope:** Enterprise Server (up to 120 days).
4353
- **Monitors:** Settings changes, permission updates, team membership, application changes.
4454
- **Limitations:** Does _not_ include Git events (pushes, pulls).
4555

46-
**Sample Query:**
4756
```graphql
4857
query {
4958
auditLogEntries(first: 20, query: "org:octo-org action:repo.cleanup") {
@@ -57,28 +66,16 @@ query {
5766
}
5867
```
5968

60-
### REST API
61-
62-
- **Scope:** Enterprise Cloud (up to 90 days; Git events for 7 days)
63-
- **Monitors:** Same as GraphQL plus Git events (push, pull, merge)
64-
65-
**Sample Request:**
66-
```http
67-
GET /orgs/{org}/audit-log?phrase=git.push
68-
Authorization: Bearer YOUR_TOKEN
69-
```
70-
71-
72-
## Investigating Missing Assets with Audit Log APIs
69+
## Investigating Missing Assets
7370

7471
To recover or audit missing resources like repositories or teams:
7572

76-
1. **Identify the asset** (e.g., `repository.deleted`).
77-
2. **Query the API** with event filters:
78-
- **REST:** `?phrase=repository.deleted`
79-
- **GraphQL:** `query auditLogEntries(query: "repository.deleted")`
80-
3. **Inspect metadata:** actor, timestamp, repository/team name.
81-
4. **Remediate:** restore from backup or revisit permissions.
73+
1. Identify the asset (e.g., `repository.deleted`).
74+
2. Query the API with event filters:
75+
- **REST:** `?phrase=repository.deleted`
76+
- **GraphQL:** `query auditLogEntries(query: "repository.deleted")`
77+
3. Inspect metadata: actor, timestamp, repository/team name.
78+
4. Remediate: restore from backup or revisit permissions.
8279

8380
```http
8481
GET /orgs/{org}/audit-log?phrase=repository.deleted
@@ -96,55 +93,68 @@ query {
9693
}
9794
```
9895

99-
10096
## Use Cases for Audit Logs
10197

102-
- **Security incidents:** Trace unauthorized access or data exfiltration.
103-
- **Compliance audits:** Demonstrate policy enforcement (SOC 2, ISO 27001).
104-
- **Operational troubleshooting:** Diagnose CI/CD failures or permission errors.
105-
- **Access monitoring:** Review API token usage and SSH/Git activity.
106-
107-
108-
## Security & Compliance with Audit Logs
98+
- **Security incidents:** Trace unauthorized access or data exfiltration.
99+
- **Compliance audits:** Demonstrate policy enforcement (SOC 2, ISO 27001).
100+
- **Operational troubleshooting:** Diagnose CI/CD failures or permission errors.
101+
- **Access monitoring:** Review API token usage and SSH/Git activity.
109102

110-
- **Data Retention:** 90 days on Enterprise Cloud; 120 days on Enterprise Server.
111-
- **Access Control:** Only owners and security managers view logs.
112-
- **IP Logging:** Records source IP to detect suspicious access.
113-
- **GDPR & Compliance:** Meets regional data-handling requirements.
103+
## Security & Compliance
114104

105+
- **Data Retention:** 90 days on Enterprise Cloud; 120 days on Enterprise Server.
106+
- **Access Control:** Only owners and security managers can view logs.
107+
- **IP Logging:** Records source IP to detect suspicious access.
108+
- **GDPR & Regional Compliance:** Meets data-handling requirements.
115109

116110
## Audit Log Streaming
117111

118112
Stream logs in real time to SIEM platforms (Splunk, Datadog) for long-term storage:
119113

120-
1. Go to **Settings > Audit log**.
121-
2. Under **Streaming**, configure a destination (AWS S3, Azure Event Hubs).
122-
3. Verify events arrive in your SIEM.
123-
114+
1. Go to **Settings > Audit log**.
115+
2. Under **Streaming**, configure a destination (AWS S3, Azure Event Hubs).
116+
3. Verify events arrive in your SIEM.
124117

125118
## Additional Audit Log Types
126119

127-
- **Git Activity Log:** Tracks pushes, pulls, merges (`phrase=git.push`).
128-
- **API Activity Log:** Tracks REST/GraphQL requests (`phrase=api.request`).
129-
- **Enterprise Managed Users (EMU):** Includes `user.login`, `repository.permissions_updated`, `repository.forked`.
130-
- **Token Usage:** Filter by `phrase=token` to identify compromised credentials.
131-
132-
133-
## Exporting Audit Logs via the Web UI
134-
135-
1. In the upper-right corner, click your profile photo, then **Your organizations**.
136-
2. Next to your organization, click **Settings**.
137-
3. In **Archive** sidebar, select **Logs**, then click **Audit log**.
138-
139-
140-
Use the **Filters** field and **Export** menu to customize and download logs.
141-
142-
143-
## Exporting Audit Logs via API
120+
- **Git Activity Log:** Tracks pushes, pulls, merges (`phrase=git.push`).
121+
- **API Activity Log:** Tracks REST/GraphQL requests (`phrase=api.request`).
122+
- **Enterprise Managed Users (EMU):** Includes `user.login`, `repository.permissions_updated`, `repository.forked`.
123+
- **Token Usage:** Filter by `phrase=token` to identify compromised credentials.
124+
125+
## Key Security Features of a GitHub Repository
126+
127+
- **SECURITY.md:** Define reporting process and supported versions.
128+
- **Branch Protection:** Enforce reviews, status checks, and commit signing.
129+
- **Dependabot Alerts:** Automatic vulnerability detection and updates.
130+
- **Code Scanning:** Continuous analysis via CodeQL.
131+
- **Secret Scanning & Push Protection:** Real-time prevention and alerts.
132+
- **Security Advisories:** Draft, collaborate, and publish advisories.
133+
- **Dependency Graph:** Visualize and audit dependencies.
134+
- **2FA & RBAC:** Enforce strong authentication and least privilege.
135+
136+
## API Access and Integrations
137+
138+
| **Token Type** | **Description** |
139+
| ------------------------- | --------------------------------------------------------------------- |
140+
| **Personal Access Tokens (PATs)** | Tied to a user account; simple scripts; broad scope. |
141+
| **Installation Tokens** | For GitHub Apps installations; fine-grained permissions. |
142+
| **OAuth Tokens** | For OAuth apps; scoped access; requires least privilege. |
143+
| **Device Tokens** | For device-based authentication flows. |
144+
| **Refresh Tokens** | To renew expired tokens without re-authentication. |
145+
146+
| **Rate Limit Type** | **Limit** |
147+
| -------------------------- | ------------------------------- |
148+
| **Unauthenticated** | 60 requests per hour. |
149+
| **Authenticated** | 5,000 requests per hour. |
150+
| **Apps** | Varies by installation. |
151+
152+
Check via API:
153+
```sh
154+
curl -H "Authorization: token YOUR_TOKEN" \
155+
-H "Accept: application/vnd.github.v3+json" \
156+
https://api.github.com/rate_limit
157+
```
144158

145-
To ensure administrators to programmatically retrieve audit log data for analysis, compliance, or monitoring purposes, GitHub provides an API endpoint for exporting audit logs. Below is the REST endpoint used for fetching audit logs:
159+
GitHub Apps offer fine-grained permissions ideal for organizational integrations, while PATs suit basic scripts. OAuth Apps should be granted least privilege, with event subscriptions managed and reviewed regularly. Organizations can restrict untrusted apps through settings to enhance security. Enterprise Managed Users provide managed accounts with limited scope, ensuring compliance. Data residency policies help organizations store logs in specified regions, aligning with regulatory requirements.
146160

147-
```http
148-
GET /orgs/{org}/audit-log
149-
Authorization: Bearer YOUR-TOKEN
150-
```

0 commit comments

Comments
 (0)