# Reverse Engineering Notes

For this research, NLS Docker-Setup is used.

[TOC]

# Appliance

The instructions assume that Docker and NLS-Stack is installed.

## Get / Copy file structure

1. Create a target directory (e.g. `mkdir /opt/nls-files`)
2. Get the Container-ID of the NLS-Appliance (`docker ps`)
3. Copy files from container \
   `docker cp -r <container-id->`

## About configuration data

- Most variables and configs are stored in `/var/lib/docker/volumes/configurations/_data`.
- Config-Variables are in `etc/dls/config/service_env.conf`.

## NLS Logs

Logs are found in `/var/lib/docker/volumes/logs/_data`.

Most interesting logs are:

- `fileInstallation.log`
- `serviceInstance.log`

## File manipulation

- Files can be copied with `docker cp <container-id>:/venv/... /opt/localfile/...`.
- Files can be directly edited via Docker-Volume mounts
    - see `df -h` (one is nls, the other postgres container)
      ```
      overlay   16G   11G  5.6G  66% /var/lib/docker/overlay2/<hash>/merged
      overlay    16G   11G  5.6G  66% /var/lib/docker/overlay2/<hash>/merged
      ```
    - then you can edit files with e.g. `nano venv/lib/python3.12/site-packages/...`

**After you edit any file directly, service needs to be restarted** `docker restart <container-id>`.

# Database

## DB Access

Valid users are `dls_writer` and `postgres`.

1. Log in to your Docker-Server
2. Get the Container-ID of the NLS-Postgres (`docker ps`)
3. Use psql \
   `docker exec -it <container-id> psql -h localhost -U postgres`
4. (optional) Create a superuser for external access \
   `CREATE USER admin WITH LOGIN SUPERUSER PASSWORD 'admin';`
5. Add exposed port to `docker-compose.yaml`
   5.1 Add `ports: [ '5432:5432' ]` into `...`-section

## Table Structure

Some information about Database / Table structure can be found [here](Database.md).

# Logging / Stack Trace

- https://docs.nvidia.com/license-system/latest/nvidia-license-system-user-guide/index.html#troubleshooting-dls-instance

# Nginx

- NGINX uses `/opt/certs/cert.pem` and `/opt/certs/key.pem`

# Other tools / files

Other tools / files which may can helpful, but not known for what they are used.

**Appliance**

- `/etc/dls/config/site_key_uri.bin`
- `/etc/dls/config/dls_db_password.bin`

**Database**

- `/etc/dls/config/decryptor/decryptor`

# Usefully commands on Client

## Check licensing status

- `nvidia-smi -q | grep "License"`

**Output**

```
vGPU Software Licensed Product
        License Status                    : Licensed (Expiry: 2023-1-14 12:59:52 GMT)
```

## Track licensing progress

- NVIDIA Grid Log: `journalctl -u nvidia-gridd -f`

```
systemd: Started NVIDIA Grid Daemon.
nvidia-gridd: Configuration parameter ( ServerAddress  ) not set
nvidia-gridd: vGPU Software package (0)
nvidia-gridd: Ignore service provider and node-locked licensing
nvidia-gridd: NLS initialized
nvidia-gridd: Acquiring license. (Info: license.nvidia.space; NVIDIA RTX Virtual Workstation)
nvidia-gridd: License acquired successfully. (Info: license.nvidia.space, NVIDIA RTX Virtual Workstation; Expiry: 2023-1-29 22:3:0 GMT)
```