Monitor OS Login audit logs

You can monitor connection attempts to virtual machine (VM) instances that have OS Login and OS Login two-factor authentication (2FA) enabled by viewing OS Login audit logs.

Before you begin

View OS Login audit logs

To display a list of OS Login connection attempts, query Cloud Audit Logs.

Console

  1. In the Google Cloud Console, go to the Logs explorer page.

    Go to Logs explorer

  2. In the Query field, enter the following query:

    protoPayload.serviceName="oslogin.googleapis.com"
    

  3. If the event you're looking for happened more than an hour ago, set a custom time frame by clicking the clock symbol and entering a custom range.

    Set query time frame.

  4. Click Run query. The results are displayed in the Query results section.

    Tip: To increase the size of the Query results section, click Enter fullscreen Query results.

  5. Click the expander arrow next to each result to show detailed information.

  6. To learn about the types of OS Login audit logs and what they mean, continue to the Review OS Login audit logs section of this document.

gcloud

  1. View Cloud Audit Logs using the gcloud logging read command:

    gcloud logging read --freshness=TIME 'protoPayload.serviceName="oslogin.googleapis.com"'
    

    Replace TIME with the amount of time you want to query. For example, 1h queries log entries in the past hour. For information about date and time formats, see gcloud topic datetimes.

    The results display.

  2. To learn about the types of OS Login audit logs and what they mean, continue to the Review OS Login audit logs section of this document.

Review OS Login audit logs

Review the methodName and principalEmail fields of the audit logs to learn about the types of connection attempts to VMs that have OS Login enabled and the users who initiated those connection attempts.

  • Expand the protoPayload section to view the methodName field for the connection attempt. To learn what each methodName field means, see the following table:

    Method Connection type Description
    google.cloud.oslogin.v1.OsLoginService.CheckPolicy All OS Login connections Indicates a connection attempt to a VM.
    google.cloud.oslogin.OsLoginService.v1.StartSession OS Login 2FA connections Indicates a new 2FA authentication session. In a StartSession call, a client declares its capabilities to the server and obtains information about the available challenges.
    google.cloud.oslogin.OsLoginService.v1.ContinueSession OS Login 2FA connections

    Indicates a continuation of an authentication session. The client completes the challenge proposed by the server on the previous StartSession call or requests and completes a different challenge type. Then, the ContinueSession method accepts the response to the challenge or method and either authenticates or rejects the authentication attempt.

  • Expand the authenticationInfo section to view the principalEmail field. The principalEmail field shows the email address of the user who tried to connect to the VM.

OS Login audit log properties

The following sections describe the properties for audit logs. Some properties are common across all audit logs, and other properties are specific to the CheckPolicy, StartSession, and ContinueSession methods.

Common OS Login audit log properties

The properties listed in the following table are common across all OS Login audit logs.

Property Value
serviceName oslogin.googleapis.com
resourceName A string containing the project number that indicates which login request the audit log belongs to. For example, projects/myproject12345.
severity The severity level of the log message. For example, INFO or WARNING. To learn more about severity levels, see LogSeverity.
authenticationInfo.principalEmail The email address of the user that the method is authenticating.
request.numericProjectId The project number of the Google Cloud project.

CheckPolicy audit log properties

The properties listed in the following table apply to CheckPolicy audit logs.

Property Value
methodName google.cloud.oslogin.v1.OsLoginService.CheckPolicy
request.@type type.googleapis.com/google.cloud.oslogin.v1.CheckPolicyRequest
request.policy The permission being checked. Either LOGIN, which checks if the user is authorized to log into the VM, or ADMIN_LOGIN, which checks if the user is authorized to have administrative access on the VM.
response.success The result of the LOGIN or ADMIN_LOGIN request.policy check. Either true or false, depending on whether the user is authorized for the specified policy.

StartSession audit log properties

The properties listed in the following table apply to StartSession audit logs, for VMs that have OS Login 2FA enabled.

Property Value
methodName google.cloud.oslogin.OsLoginService.v1.StartSession
request.@type type.googleapis.com/google.cloud.oslogin.OsLoginService.v1.StartSessionRequest
request.supportedChallengeTypes The list of challenge types or 2FA methods that you can choose from.
response.authenticationStatus Status of the session. One of Authenticated, Challenge required, or Challenge pending.
response.sessionId An ID string uniquely identifying the session. This session ID is passed to the ContinueSession call in the sequence.
response.challenges The set of challenges that you can attempt to pass during this round of authentication. At most, one of these challenges is started and has a status of READY. The others are provided as options that the user can specify as an alternative to the proposed primary challenge.

ContinueSession audit log properties

The properties listed in the following table apply to ContinueSession audit logs, for VMs that have OS Login 2FA enabled.

Property Value
methodName google.cloud.oslogin.OsLoginService.v1.ContinueSession
request.sessionId An ID string uniquely identifying the previous session. This session ID is passed from the StartSession call.
request.@type type.googleapis.com/google.cloud.oslogin.OsLoginService.v1.ContinueSessionRequest
request.challengeId An ID string identifying which challenge to start or execute. This ID must belong to a challenge type returned from the response.challenges call in the StartSession response.
request.action The action to take to complete the challenge.
response.authenticationStatus Status of the session. For example, Authenticated, Challenge required, or Challenge pending.
response.challenges.status SUCCESS indicates that a user has successfully connected to the VM.
response.challenges The set of challenges that you can attempt to pass this round of authentication. At most, one of these challenges is started and has a status of READY. The others are provided as options that the user can specify as an alternative to the proposed primary challenge.

What's next?