Skip to content

Commit

Permalink
Implement a complexity checker for api_secret
Browse files Browse the repository at this point in the history
Set remote execution as a boolean flag
  • Loading branch information
dormant-user committed Aug 11, 2024
1 parent c3d01d3 commit 77284df
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 22 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ pyninja start
- **NINJA_HOST** - Hostname for the API server.
- **NINJA_PORT** - Port number for the API server.
- **WORKERS** - Number of workers for the uvicorn server.
- **COMMAND_TIMEOUT** - Number of seconds for a command to timeout.
- **REMOTE_EXECUTION** - Boolean flag to enable remote execution.
- **API_SECRET** - Secret access key for running commands on server remotely.
- **APIKEY** - API Key for authentication.

**COMMAND_TIMEOUT** is set to `0` by default, disabling remote executions. To enable it, set it to a value greater than `0`<br>
⚠️ Enabling remote execution can be extremely risky and can be a major security threat. So use **caution** and set the **API_SECRET** to a strong value.

> `PyNinja` supports [logging.ini] configuration for custom logging. Just place it in the current working directory.<br>
Expand Down
5 changes: 2 additions & 3 deletions docs/README.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,11 @@ <h2>Environment Variables<a class="headerlink" href="#environment-variables" tit
<li><p><strong>NINJA_HOST</strong> - Hostname for the API server.</p></li>
<li><p><strong>NINJA_PORT</strong> - Port number for the API server.</p></li>
<li><p><strong>WORKERS</strong> - Number of workers for the uvicorn server.</p></li>
<li><p><strong>COMMAND_TIMEOUT</strong> - Number of seconds for a command to timeout.</p></li>
<li><p><strong>REMOTE_EXECUTION</strong> - Boolean flag to enable remote execution.</p></li>
<li><p><strong>API_SECRET</strong> - Secret access key for running commands on server remotely.</p></li>
<li><p><strong>APIKEY</strong> - API Key for authentication.</p></li>
</ul>
<p><strong>COMMAND_TIMEOUT</strong> is set to <code class="docutils literal notranslate"><span class="pre">0</span></code> by default, disabling remote executions. To enable it, set it to a value greater than <code class="docutils literal notranslate"><span class="pre">0</span></code><br>
⚠️ Enabling remote execution can be extremely risky and can be a major security threat. So use <strong>caution</strong> and set the <strong>API_SECRET</strong> to a strong value.</p>
<p>⚠️ Enabling remote execution can be extremely risky and can be a major security threat. So use <strong>caution</strong> and set the <strong>API_SECRET</strong> to a strong value.</p>
<blockquote>
<div><p><code class="docutils literal notranslate"><span class="pre">PyNinja</span></code> supports <a class="reference external" href="https://docs.python-guide.org/writing/logging/#example-configuration-via-an-ini-file">logging.ini</a> configuration for custom logging. Just place it in the current working directory.<br>
Refer <a class="reference external" href="https://github.com/thevickypedia/PyNinja/tree/main/samples">samples</a> directory for examples.</p>
Expand Down
3 changes: 1 addition & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ pyninja start
- **NINJA_HOST** - Hostname for the API server.
- **NINJA_PORT** - Port number for the API server.
- **WORKERS** - Number of workers for the uvicorn server.
- **COMMAND_TIMEOUT** - Number of seconds for a command to timeout.
- **REMOTE_EXECUTION** - Boolean flag to enable remote execution.
- **API_SECRET** - Secret access key for running commands on server remotely.
- **APIKEY** - API Key for authentication.

**COMMAND_TIMEOUT** is set to `0` by default, disabling remote executions. To enable it, set it to a value greater than `0`<br>
⚠️ Enabling remote execution can be extremely risky and can be a major security threat. So use **caution** and set the **API_SECRET** to a strong value.

> `PyNinja` supports [logging.ini] configuration for custom logging. Just place it in the current working directory.<br>
Expand Down
3 changes: 1 addition & 2 deletions docs/_sources/README.md.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ pyninja start
- **NINJA_HOST** - Hostname for the API server.
- **NINJA_PORT** - Port number for the API server.
- **WORKERS** - Number of workers for the uvicorn server.
- **COMMAND_TIMEOUT** - Number of seconds for a command to timeout.
- **REMOTE_EXECUTION** - Boolean flag to enable remote execution.
- **API_SECRET** - Secret access key for running commands on server remotely.
- **APIKEY** - API Key for authentication.

**COMMAND_TIMEOUT** is set to `0` by default, disabling remote executions. To enable it, set it to a value greater than `0`<br>
⚠️ Enabling remote execution can be extremely risky and can be a major security threat. So use **caution** and set the **API_SECRET** to a strong value.

> `PyNinja` supports [logging.ini] configuration for custom logging. Just place it in the current working directory.<br>
Expand Down
26 changes: 25 additions & 1 deletion docs/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ <h1 id="index">Index</h1>
| <a href="#E"><strong>E</strong></a>
| <a href="#F"><strong>F</strong></a>
| <a href="#G"><strong>G</strong></a>
| <a href="#H"><strong>H</strong></a>
| <a href="#M"><strong>M</strong></a>
| <a href="#N"><strong>N</strong></a>
| <a href="#P"><strong>P</strong></a>
| <a href="#R"><strong>R</strong></a>
| <a href="#S"><strong>S</strong></a>
| <a href="#T"><strong>T</strong></a>
| <a href="#U"><strong>U</strong></a>
| <a href="#W"><strong>W</strong></a>

Expand Down Expand Up @@ -80,7 +82,7 @@ <h2 id="C">C</h2>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="index.html#pyninja.squire.EnvConfig.command_timeout">command_timeout (pyninja.squire.EnvConfig attribute)</a>
<li><a href="index.html#pyninja.squire.complexity_checker">complexity_checker() (in module pyninja.squire)</a>
</li>
</ul></td>
</tr></table>
Expand Down Expand Up @@ -137,6 +139,14 @@ <h2 id="G">G</h2>
</ul></td>
</tr></table>

<h2 id="H">H</h2>
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="index.html#pyninja.squire.EnvConfig.Config.hide_input_in_errors">hide_input_in_errors (pyninja.squire.EnvConfig.Config attribute)</a>
</li>
</ul></td>
</tr></table>

<h2 id="M">M</h2>
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%; vertical-align: top;"><ul>
Expand Down Expand Up @@ -177,6 +187,8 @@ <h2 id="N">N</h2>
<h2 id="P">P</h2>
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="index.html#pyninja.squire.EnvConfig.parse_api_secret">parse_api_secret() (pyninja.squire.EnvConfig class method)</a>
</li>
<li><a href="index.html#pyninja.squire.Payload">Payload (class in pyninja.squire)</a>
</li>
<li><a href="index.html#pyninja.routers.process_status">process_status() (in module pyninja.routers)</a>
Expand Down Expand Up @@ -237,6 +249,10 @@ <h2 id="P">P</h2>

<h2 id="R">R</h2>
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="index.html#pyninja.squire.EnvConfig.remote_execution">remote_execution (pyninja.squire.EnvConfig attribute)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="index.html#pyninja.routers.run_command">run_command() (in module pyninja.routers)</a>
</li>
Expand All @@ -259,6 +275,14 @@ <h2 id="S">S</h2>
</ul></td>
</tr></table>

<h2 id="T">T</h2>
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="index.html#pyninja.squire.Payload.timeout">timeout (pyninja.squire.Payload attribute)</a>
</li>
</ul></td>
</tr></table>

<h2 id="U">U</h2>
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%; vertical-align: top;"><ul>
Expand Down
53 changes: 51 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ <h1>Squire<a class="headerlink" href="#squire" title="Permalink to this heading"
<span class="sig-name descname"><span class="pre">command</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="pre">str</span></em><a class="headerlink" href="#pyninja.squire.Payload.command" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

<dl class="py attribute">
<dt class="sig sig-object py" id="pyninja.squire.Payload.timeout">
<span class="sig-name descname"><span class="pre">timeout</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="pre">Union</span><span class="p"><span class="pre">[</span></span><span class="pre">int</span><span class="p"><span class="pre">,</span></span><span class="w"> </span><span class="pre">float</span><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#pyninja.squire.Payload.timeout" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

</dd></dl>

<hr class="docutils" />
Expand Down Expand Up @@ -296,8 +301,8 @@ <h1>Squire<a class="headerlink" href="#squire" title="Permalink to this heading"
<dd></dd></dl>

<dl class="py attribute">
<dt class="sig sig-object py" id="pyninja.squire.EnvConfig.command_timeout">
<span class="sig-name descname"><span class="pre">command_timeout</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="pre">int</span></em><a class="headerlink" href="#pyninja.squire.EnvConfig.command_timeout" title="Permalink to this definition"></a></dt>
<dt class="sig sig-object py" id="pyninja.squire.EnvConfig.remote_execution">
<span class="sig-name descname"><span class="pre">remote_execution</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="pre">bool</span></em><a class="headerlink" href="#pyninja.squire.EnvConfig.remote_execution" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

<dl class="py attribute">
Expand All @@ -310,6 +315,23 @@ <h1>Squire<a class="headerlink" href="#squire" title="Permalink to this heading"
<span class="sig-name descname"><span class="pre">apikey</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="pre">str</span></em><a class="headerlink" href="#pyninja.squire.EnvConfig.apikey" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="pyninja.squire.EnvConfig.parse_api_secret">
<em class="property"><span class="pre">classmethod</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">parse_api_secret</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">value</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><span class="pre">None</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">str</span><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><span class="pre">None</span></span></span><a class="headerlink" href="#pyninja.squire.EnvConfig.parse_api_secret" title="Permalink to this definition"></a></dt>
<dd><p>Parse API secret to validate complexity.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>value</strong> – Takes the user input as an argument.</p>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>Returns the parsed value.</p>
</dd>
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p>str</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="pyninja.squire.EnvConfig.from_env_file">
<em class="property"><span class="pre">classmethod</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">from_env_file</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">env_file</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">Optional</span><span class="p"><span class="pre">[</span></span><span class="pre">str</span><span class="p"><span class="pre">]</span></span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference internal" href="#pyninja.squire.EnvConfig" title="pyninja.squire.EnvConfig"><span class="pre">EnvConfig</span></a></span></span><a class="headerlink" href="#pyninja.squire.EnvConfig.from_env_file" title="Permalink to this definition"></a></dt>
Expand All @@ -336,12 +358,39 @@ <h1>Squire<a class="headerlink" href="#squire" title="Permalink to this heading"
<span class="sig-name descname"><span class="pre">extra</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">'ignore'</span></em><a class="headerlink" href="#pyninja.squire.EnvConfig.Config.extra" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

<dl class="py attribute">
<dt class="sig sig-object py" id="pyninja.squire.EnvConfig.Config.hide_input_in_errors">
<span class="sig-name descname"><span class="pre">hide_input_in_errors</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">True</span></em><a class="headerlink" href="#pyninja.squire.EnvConfig.Config.hide_input_in_errors" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

</dd></dl>

</dd></dl>

<hr class="docutils" />
<span class="target" id="module-pyninja.squire"></span><dl class="py function">
<dt class="sig sig-object py" id="pyninja.squire.complexity_checker">
<span class="sig-prename descclassname"><span class="pre">pyninja.squire.</span></span><span class="sig-name descname"><span class="pre">complexity_checker</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">secret</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">None</span></span></span><a class="headerlink" href="#pyninja.squire.complexity_checker" title="Permalink to this definition"></a></dt>
<dd><p>Verifies the strength of a secret.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p>A secret is considered strong if it at least has:</p>
<ul class="simple">
<li><p>32 characters</p></li>
<li><p>1 digit</p></li>
<li><p>1 symbol</p></li>
<li><p>1 uppercase letter</p></li>
<li><p>1 lowercase letter</p></li>
</ul>
</div>
<dl class="field-list simple">
<dt class="field-odd">Raises<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>AssertionError</strong> – When at least 1 of the above conditions fail to match.</p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="pyninja.squire.env_loader">
<span class="sig-prename descclassname"><span class="pre">pyninja.squire.</span></span><span class="sig-name descname"><span class="pre">env_loader</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">filename</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><span class="pre">os.PathLike</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference internal" href="#pyninja.squire.EnvConfig" title="pyninja.squire.EnvConfig"><span class="pre">EnvConfig</span></a></span></span><a class="headerlink" href="#pyninja.squire.env_loader" title="Permalink to this definition"></a></dt>
<dd><p>Loads environment variables based on filetypes.</p>
Expand Down
Binary file modified docs/objects.inv
Binary file not shown.
Loading

0 comments on commit 77284df

Please sign in to comment.