> For the complete documentation index, see [llms.txt](https://docs.octoxlabs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.octoxlabs.com/adapters/l/lockfy-db.md).

# Lockfy DB

|                              |                                                   |
| ---------------------------- | ------------------------------------------------- |
| Category                     | Endpoint security                                 |
| Asset types                  | Devices, Users                                    |
| Authentication               | SQL Server login (SQL authentication or Kerberos) |
| Direction                    | OctoXLabs → Lockfy DB (read only)                 |
| Supported Lockfy DB versions | Not specified                                     |
| Available since              | Not specified                                     |

Lockfy is an endpoint security product that stores its data in a Microsoft SQL Server database. This adapter reads that database directly. OctoXLabs adds the workstations, their installed applications and browser extensions, and the Lockfy users to its inventories.

## Use cases

* **Find Lockfy workstations without another agent.** List workstations that Lockfy reports but CrowdStrike does not.

```
Adapters = lockfy-db AND NOT Adapters = falcon-crowdstrike
```

* **List Windows workstations.** Filter on the OS type.

```
Adapters = lockfy-db AND OS.Type = Windows
```

## Before you begin

### Network

| Source              | Destination                            | Port                | Protocol         |
| ------------------- | -------------------------------------- | ------------------- | ---------------- |
| OctoXLabs connector | SQL Server host of the Lockfy database | 1433 (configurable) | TCP (SQL Server) |

With Kerberos, the connector must also reach the KDC.

### Required permissions

| Scope or role                                | Permission | Needed for                                            |
| -------------------------------------------- | ---------- | ----------------------------------------------------- |
| Read, Select and List on the Lockfy database | Read       | Workstations, applications, browser extensions, users |

The baseline says the user must have Read, Select and List privileges.

## Create credentials in Lockfy DB

{% stepper %}
{% step %}

### Open SQL Server Management Studio

Connect to the SQL Server that hosts the Lockfy database.
{% endstep %}

{% step %}

### Create a login

Select the **authentication** used in the server and fill in the details. Select your database in **Default Database**.
{% endstep %}

{% step %}

### Grant read access

Give the user **Read**, **Select** and **List** privileges.
{% endstep %}

{% step %}

### Save and sign in once

Save the user. Log in to the database with this user once to avoid an error.
{% endstep %}
{% endstepper %}

{% hint style="info" %}
If **Custom Query** and **View Name** are both empty, the default query for each enabled asset type runs. With a custom query or view, the column names must match what the adapter expects (for example `Hostname`, `OperatingSystemName`, `LastKnownIpAddress`), otherwise the fields stay empty.
{% endhint %}

{% hint style="info" %}
With **Use PyODBC Driver** or Kerberos, ODBC Driver 17 or 18 for SQL Server must be installed on the connector machine. For SQL authentication the connector tries Driver 17 first, then Driver 18. For Kerberos it tries Driver 18 first.
{% endhint %}

{% hint style="info" %}
**Kerberos (optional).** Set Auth Type to Kerberos to use Active Directory credentials. In password mode the connector uses the username and password to get a ticket. In keytab mode you upload a keytab generated with `ktpass` and no password is needed. After connecting, query `sys.dm_exec_connections` and confirm `auth_scheme` is `KERBEROS`.
{% endhint %}

## Connection parameters

| Parameter                | Required    | Type    | Default  | Description                                                                                            |
| ------------------------ | ----------- | ------- | -------- | ------------------------------------------------------------------------------------------------------ |
| IP or Domain             | Yes         | String  | None     | IP address or host of the SQL Server.                                                                  |
| Port                     | No          | Integer | 1433     | SQL Server port.                                                                                       |
| Domain                   | No          | String  | None     | Domain FQDN. When set, the login is sent as `domain\username`.                                         |
| Database                 | Yes         | String  | None     | Name of the database.                                                                                  |
| Username                 | Yes         | String  | None     | SQL Server login.                                                                                      |
| Password                 | Conditional | String  | None     | Required for SQL authentication and for Kerberos Mode password. May be empty for Kerberos Mode keytab. |
| View Name                | No          | String  | None     | Name of a SQL Server view. When set, the adapter runs `SELECT * FROM <view>` for devices.              |
| Custom Query             | No          | String  | None     | Custom SQL query for devices. It takes priority over View Name.                                        |
| Fetch Devices            | No          | Boolean | True     | Fetch workstations.                                                                                    |
| Fetch Users              | No          | Boolean | False    | Fetch users.                                                                                           |
| Query Timeout            | No          | Integer | 60       | Maximum seconds for a query.                                                                           |
| Use PyODBC Driver        | No          | Boolean | False    | Use pyodbc instead of pymssql.                                                                         |
| Batch Size               | No          | Integer | 300      | Rows fetched per batch.                                                                                |
| Auth Type                | No          | String  | SQL      | `SQL` or `Kerberos`.                                                                                   |
| Kerberos Mode            | No          | String  | password | `password` or `keytab`.                                                                                |
| Kerberos Realm           | No          | String  | None     | Realm in uppercase, for example `CORP.LOCAL`. Optional with a UPN username.                            |
| KDC IP                   | No          | String  | None     | Host name or IP of the KDC.                                                                            |
| Kerberos SPN             | No          | String  | None     | SPN override, for example `MSSQLSvc/sqlserver.corp.local:1433`.                                        |
| Keytab                   | Conditional | File    | None     | Required when Kerberos Mode is keytab.                                                                 |
| Encrypt                  | No          | Boolean | True     | TLS between client and server. Applied only with Kerberos.                                             |
| Trust Server Certificate | No          | Boolean | True     | Skip certificate chain validation. Applied only with Kerberos.                                         |

## What the connection test does

The test opens a connection to the database. With Kerberos it also checks that `auth_scheme` is `KERBEROS`.

## API endpoints called

| Method | Path                                                                        | Purpose                                               |
| ------ | --------------------------------------------------------------------------- | ----------------------------------------------------- |
| SQL    | dbo.Workstations joined with dbo.OperatingSystemsInfo                       | Default device query.                                 |
| SQL    | dbo.WorkstationsInstalledApplications joined with dbo.Applications          | Installed applications of each batch of workstations. |
| SQL    | dbo.WorkstationInstalledBrowserExtensions joined with dbo.BrowserExtensions | Browser extensions of each batch.                     |
| SQL    | dbo.Users                                                                   | Default user query. Only with Fetch Users.            |

Lockfy is read through SQL, not an HTTP API.

## Fields fetched

### Devices

| Lockfy DB field                                         | OctoXLabs field                       |
| ------------------------------------------------------- | ------------------------------------- |
| Hostname (name, plus \_DomainName when a domain exists) | Hostname (primary identifier)         |
| OperatingSystemName                                     | OS.FullOsString, OS.Type and Category |
| LastKnownIpAddress                                      | IpAddresses                           |
| AgentBuildNumber                                        | AgentVersions (lockfy)                |
| Application rows                                        | InstalledSoftware                     |

### Users

| Lockfy DB field | OctoXLabs field            |
| --------------- | -------------------------- |
| Email           | Email (primary identifier) |

Browser extensions are attached to each device as raw data but are not mapped to an OctoXLabs field in this adapter.

## Troubleshooting

| Error message                                                                                                             | Cause                                                                                                                                                                                                                                            | Fix                                                                                                                                                                     |
| ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| You must enable at least one of the following options: fetch\_devices or fetch\_users.                                    | Both Fetch Devices and Fetch Users are off.                                                                                                                                                                                                      | Turn on at least one.                                                                                                                                                   |
| MSSQL query failed \[{label}]: {cause}; {n} row(s) read before failure. Detail: {detail}                                  | A SQL query failed. The cause is one of: query or connection timeout (DB-Lib 20003), connection dropped (DB-Lib 20047), no result set, read from server failed (DB-Lib 20004), login or authentication failure, or an unexpected database error. | Use the cause text in the message. Check network and firewall for dropped connections, raise Query Timeout for timeouts, and verify the credentials for login failures. |
| No ODBC Driver found. Install 'ODBC Driver 17' or 'ODBC Driver 18' for SQL Server.                                        | Use PyODBC Driver is on but neither driver is installed on the connector host.                                                                                                                                                                   | Install ODBC Driver 17 or 18 for SQL Server, or turn the option off.                                                                                                    |
| Password is required for SQL Server Authentication.                                                                       | Auth Type is SQL and the password is empty.                                                                                                                                                                                                      | Enter the password.                                                                                                                                                     |
| Keytab is required when kerberos\_mode is 'keytab'.                                                                       | Kerberos Mode is keytab and no keytab was uploaded.                                                                                                                                                                                              | Upload the keytab file.                                                                                                                                                 |
| Password is required when kerberos\_mode is 'password'.                                                                   | Kerberos Mode is password and the password is empty.                                                                                                                                                                                             | Enter the password.                                                                                                                                                     |
| Kerberos config failed: SQL Server reports auth\_scheme='{scheme}'. Check SPN registration in AD and the Encrypt setting. | The connection works but SQL Server did not use Kerberos, for example because of a wrong SPN.                                                                                                                                                    | Check the SPN registration in Active Directory and the Encrypt setting.                                                                                                 |
| Kerberos authentication failed: wrong password or pre-authentication rejected.                                            | The KDC rejected the credentials.                                                                                                                                                                                                                | Check the username and password.                                                                                                                                        |
| Cannot reach KDC. Check the kdc\_ip value and network/firewall.                                                           | The KDC is not reachable.                                                                                                                                                                                                                        | Check KDC IP and the firewall.                                                                                                                                          |
| Clock skew between client and KDC is too large. Sync the system clock.                                                    | Time differs too much between the connector and the KDC.                                                                                                                                                                                         | Synchronize the clock.                                                                                                                                                  |
| Principal not found in Active Directory. Check the realm and username.                                                    | The Kerberos principal does not exist.                                                                                                                                                                                                           | Check the realm and username.                                                                                                                                           |
| Keytab does not contain a matching key for the principal.                                                                 | The keytab does not match the account.                                                                                                                                                                                                           | Generate the keytab again for this principal.                                                                                                                           |
| Encryption type mismatch between client/keytab and KDC.                                                                   | No common encryption type.                                                                                                                                                                                                                       | Check the encryption types of the account and keytab.                                                                                                                   |

## Change history
