test new build
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2023-12-28 15:30:58 +11:00
parent ca39234f12
commit 6f47262336
5 changed files with 374 additions and 10 deletions

253
index.htm Normal file
View File

@@ -0,0 +1,253 @@
<h1>Secrets Management Tool (SMT)</h1>
<p>Build Date: {BUILDTIME}
Build Hash: {SHA1VER}</p>
<h2>Overview</h2>
<p>Provide REST API for CRUD to store and retrieve secrets. Only password is encrypted, via AES256 GCM. Values stored encrypted within a sqlite database.</p>
<p>A successful authentication returns a JWT token which must be provided for all other operations.</p>
<p>Multiple user roles are supported, with each user only able to access secrets matching their user role. One exception is the built in administrator role that is able to access all secrets.</p>
<p>Written by Nathan Coad (nathan.coad@dell.com)</p>
<h2>Installation</h2>
<ol>
<li>Copy binary to chosen location, eg /srv/smt/smt</li>
<li>Create .env file in same directory as binary, populate as per Configuration section below</li>
<li>Create systemd service definition</li>
<li>Start service</li>
</ol>
<h2>Configuration</h2>
<table>
<thead>
<tr>
<th>Environment Variable Name</th>
<th>Description</th>
<th>Example</th>
<th>Default</th>
</tr>
</thead>
<tbody>
<tr>
<td>LOG_FILE</td>
<td>Specify the name/path of file to write log messages to</td>
<td>/var/log/smt.log</td>
<td>./smt.log</td>
</tr>
<tr>
<td>BIND_IP</td>
<td>Specify the local IP address to bind to.</td>
<td>127.0.0.1</td>
<td>Primary IPv4 address</td>
</tr>
<tr>
<td>BIND_PORT</td>
<td>Specify the TCP/IP port to bind to.</td>
<td>443</td>
<td>8443</td>
</tr>
<tr>
<td>TLS_KEY_FILE</td>
<td>Specify the filename of the TLS certificate private key (must be unencrypted) in PEM format</td>
<td>key.pem</td>
<td>privkey.pem</td>
</tr>
<tr>
<td>TLS_CERT_FILE</td>
<td>Specify the filename of the TLS certificate file in PEM format</td>
<td>cert.pem</td>
<td>cert.pem</td>
</tr>
<tr>
<td>TOKEN_HOUR_LIFESPAN</td>
<td>Number of hours that the JWT token returned at login is valid</td>
<td>12</td>
<td>No default specified, must define this value</td>
</tr>
<tr>
<td>API_SECRET</td>
<td>Secret to use when generating JWT token</td>
<td>3c55990bd479322e2053db3a8</td>
<td>No default specified, must define this value</td>
</tr>
<tr>
<td>INITIAL_PASSWORD</td>
<td>Password to set for builtin Administrator account created when first started, can remove this value after first start. Can specify in plaintext or bcrypt hash</td>
<td>$2a$10$s39a82wrRAdOJVZEkkrSReVnXprz5mxU30ZBO.dHPYTncQCsUD9ce</td>
<td>password</td>
</tr>
<tr>
<td>SECRETS_KEY</td>
<td>Key to use for AES256 GCM encryption. Must be exactly 32 bytes</td>
<td>AES256Key-32Characters1234567890</td>
<td>No default specified, must define this value or use /api/unlock at runtime</td>
</tr>
</tbody>
</table>
<p>If the TLS certificate and key files cannot be located in the specified location, a self signed certificate will be generated with a 1 year validity period.</p>
<p>Example for generating API_SECRET and SECRETS_KEY is the following command on linux: <code>head /dev/urandom | tr -dc A-Za-z0-9 | head -c32</code></p>
<h2>Systemd script</h2>
<p>Create/update the systemd service definition at /etc/systemd/system/smt.service and then run systemctl daemon-reload</p>
<pre><code>[Unit]
Description=Secrets Management Tool
After=network.target
#StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=root
ExecStart=/srv/smt/smt
[Install]
WantedBy=multi-user.target
</code></pre>
<h2>API</h2>
<h3>Unlock</h3>
<p>POST <code>/api/unlock</code></p>
<p>Data</p>
<pre><code>{
&quot;secretKey&quot;: &quot;Example32ByteSecretKey0123456789&quot;
}
</code></pre>
<p>If the SECRETS_KEY environment variable is not defined, this API call to unlock stored secrets must be performed after initial startup of SMT. Storing/retrieval of secrets will not succeed until this API call has been made.</p>
<h3>User Operations</h3>
<h4>Register</h4>
<p>POST <code>/api/admin/register</code></p>
<p>Data</p>
<pre><code>{
&quot;username&quot;: &quot;&quot;,
&quot;password&quot;: &quot;&quot;,
&quot;RoleId&quot;: 2
}
</code></pre>
<p>This operation can only be performed by a user with a role that is admin enabled. There are 3 built in roles, which can be viewed via the <code>/api/admin/roles</code> endpoint.</p>
<h4>Login</h4>
<p>POST <code>/api/login</code></p>
<p>Data</p>
<pre><code>{
&quot;username&quot;: &quot;&quot;,
&quot;password&quot;: &quot;&quot;
}
</code></pre>
<p>This API call will return a JWT token that must be present for any other API calls to succeed. The validity duration of this token is based on the configured TOKEN_HOUR_LIFESPAN value. JWT token is returned as value of <code>access_token</code>.</p>
<h4>List Roles</h4>
<p>GET <code>/api/admin/roles</code></p>
<p>This operation can only be performed by a user with a role that is admin enabled. Lists currently defined roles.</p>
<h4>List Users</h4>
<p>GET <code>/api/admin/users</code></p>
<p>This operation can only be performed by a user with a role that is admin enabled. Lists currently defined users.</p>
<h3>Secrets Operations</h3>
<h4>Store</h4>
<p>POST <code>/api/secret/store</code></p>
<p>Data</p>
<pre><code>{
&quot;deviceName&quot;: &quot;&quot;,
&quot;deviceCategory&quot;: &quot;&quot;,
&quot;userName&quot;: &quot;&quot;,
&quot;secretValue&quot;: &quot;&quot;
}
</code></pre>
<p>Must be logged in to execute this command. Role of current user cannot be a ReadOnly role. Secret will be stored with the RoleId of the currently logged in user. Either deviceName or deviceCategory can be blank but not both.</p>
<p>If a secret exists for this RoleId and matching deviceName and deviceCategory then an error will be generated.</p>
<h4>Retrieve</h4>
<p>POST <code>/api/secret/retrieve</code></p>
<p>Data</p>
<pre><code>{
&quot;deviceName&quot;: &quot;&quot;,
&quot;deviceCategory&quot;: &quot;&quot;,
&quot;userName&quot;: &quot;&quot;
}
</code></pre>
<p>Must be logged in to execute this command. Only secrets registered with the current user&rsquo;s RoleId can be retrieved.</p>
<p>Either deviceName or deviceCategory can be specified (or both). Wildcards are supported for both deviceName and deviceCategory fields. userName can also be specified in conjunction with deviceName or deviceCategory.
1. The percent sign % wildcard matches any sequence of zero or more characters.
2. The underscore _ wildcard matches any single character.</p>
<p>GET <code>/api/secret/retrieve/name/&lt;searchname&gt;</code></p>
<p>Search for a secret specified by deviceName using a GET request.
Must be logged in to execute this command. Only secrets registered with the current user&rsquo;s RoleId can be retrieved.</p>
<p>GET <code>/api/secret/retrieve/category/&lt;searchname&gt;</code></p>
<p>Search for a secret specified by deviceCategory using a GET request.
Must be logged in to execute this command. Only secrets registered with the current user&rsquo;s RoleId can be retrieved.</p>
<h4>Update</h4>
<p>POST <code>/api/secret/update</code></p>
<p>Data</p>
<pre><code>{
&quot;deviceName&quot;: &quot;&quot;,
&quot;deviceCategory&quot;: &quot;&quot;,
&quot;userName&quot;: &quot;&quot;,
&quot;secretValue&quot;: &quot;&quot;
}
</code></pre>
<p>Users with ReadOnly role will receive Forbidden error when calling this API endpoint. The values specified in deviceName and deviceCategory must match exactly one existing secret record for the RoleId of the currently logged in user. Wildcards are supported for deviceName and deviceCategory.</p>
<h4>List</h4>
<p>GET <code>/api/secret/list</code></p>
<p>Will generate a list of device names and categories but not secret data.</p>