splunksecrets 0.5.0__tar.gz โ†’ 1.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,52 @@
1
+ name: Publish Python ๐Ÿ distribution ๐Ÿ“ฆ to PyPI
2
+
3
+ on: push
4
+
5
+ jobs:
6
+ build:
7
+ name: Build distribution ๐Ÿ“ฆ
8
+ runs-on: ubuntu-latest
9
+
10
+ steps:
11
+ - uses: actions/checkout@v4
12
+ with:
13
+ persist-credentials: false
14
+ - name: Set up Python
15
+ uses: actions/setup-python@v5
16
+ with:
17
+ python-version: "3.x"
18
+ - name: Install pypa/build
19
+ run: >-
20
+ python3 -m
21
+ pip install
22
+ build
23
+ --user
24
+ - name: Build a binary wheel and a source tarball
25
+ run: python3 -m build
26
+ - name: Store the distribution packages
27
+ uses: actions/upload-artifact@v4
28
+ with:
29
+ name: python-package-distributions
30
+ path: dist/
31
+
32
+ publish-to-pypi:
33
+ name: >-
34
+ Publish Python ๐Ÿ distribution ๐Ÿ“ฆ to PyPI
35
+ if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
36
+ needs:
37
+ - build
38
+ runs-on: ubuntu-latest
39
+ environment:
40
+ name: pypi
41
+ url: https://pypi.org/p/splunksecrets
42
+ permissions:
43
+ id-token: write
44
+
45
+ steps:
46
+ - name: Download all the dists
47
+ uses: actions/download-artifact@v4
48
+ with:
49
+ name: python-package-distributions
50
+ path: dist/
51
+ - name: Publish distribution ๐Ÿ“ฆ to PyPI
52
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,41 @@
1
+ name: Tests
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - "*"
7
+ pull_request:
8
+ branches:
9
+ - master
10
+ workflow_dispatch:
11
+
12
+ jobs:
13
+ main-lint-test:
14
+ runs-on: ubuntu-latest
15
+ strategy:
16
+ matrix:
17
+ python-version:
18
+ - "3.9"
19
+ - "3.10"
20
+ - "3.11"
21
+ - "3.12"
22
+ - "3.13"
23
+
24
+ steps:
25
+ - name: ๐Ÿ›Ž๏ธ Checkout
26
+ uses: actions/checkout@v4
27
+
28
+ - name: ๐Ÿ“ฆ Install uv
29
+ uses: astral-sh/setup-uv@v5
30
+
31
+ - name: ๐Ÿ Set up Python
32
+ uses: actions/setup-python@v5
33
+
34
+ - name: ๐Ÿš€ Install just
35
+ uses: extractions/setup-just@v2
36
+
37
+ - name: ๐Ÿฆพ Install the project
38
+ run: just dev-sync
39
+
40
+ - name: ๐Ÿ’… ๐Ÿงช Format, Lint and test
41
+ run: just validate
@@ -0,0 +1,72 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+
5
+ # C extensions
6
+ *.so
7
+
8
+ # Distribution / packaging
9
+ .Python
10
+ env/
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ lib/
17
+ lib64/
18
+ parts/
19
+ sdist/
20
+ var/
21
+ *.egg-info/
22
+ .installed.cfg
23
+ *.egg
24
+ .python-version
25
+
26
+ # PyInstaller
27
+ # Usually these files are written by a python script from a template
28
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
29
+ *.manifest
30
+ *.spec
31
+
32
+ # Installer logs
33
+ pip-log.txt
34
+ pip-delete-this-directory.txt
35
+
36
+ # Unit test / coverage reports
37
+ htmlcov/
38
+ .tox/
39
+ .coverage
40
+ .coverage_data
41
+ .cache
42
+ nosetests.xml
43
+ coverage.xml
44
+
45
+ # Translations
46
+ *.mo
47
+ *.pot
48
+
49
+ # Django stuff:
50
+ *.log
51
+
52
+ # Sphinx documentation
53
+ docs/_build/
54
+
55
+ # PyBuilder
56
+ target/
57
+
58
+ #Vim
59
+ *.swp
60
+
61
+ # Divshot
62
+ .divshot-cache/
63
+ .venv
64
+ splunk.secret
65
+ .vscode/**
66
+ .pytest_cache/**
67
+ .venv-py27
68
+ secret.gh*
69
+ test_phantom_private_key.pem
70
+ test_phantom_secret_key.py
71
+ test_splunk.secret
72
+ test_identity.dat
@@ -0,0 +1,28 @@
1
+ # https://github.com/casey/just
2
+
3
+ dev-sync:
4
+ uv sync --all-extras --cache-dir .uv_cache
5
+
6
+ prod-sync:
7
+ uv sync --all-extras --no-dev --cache-dir .uv_cache
8
+
9
+ install-hooks:
10
+ uv run pre-commit install
11
+
12
+ format:
13
+ uv run ruff format
14
+
15
+ lint:
16
+ uv run ruff check --fix
17
+ test:
18
+ uv run pytest --verbose --color=yes tests
19
+
20
+ validate: format lint test
21
+
22
+ dockerize:
23
+ docker build -t python-repo-template .
24
+
25
+ # Use it like:
26
+ # just run 10
27
+ run number:
28
+ uv run main.py --number {{number}}
@@ -0,0 +1,10 @@
1
+ Metadata-Version: 2.4
2
+ Name: splunksecrets
3
+ Version: 1.1.0
4
+ Summary: Command-line tools for working with secrets for Splunk products
5
+ Author: Steve McMaster, Cameron Schmidt
6
+ Maintainer: Cameron Schmidt
7
+ Requires-Python: >=3.9
8
+ Requires-Dist: click>=8.0.0
9
+ Requires-Dist: cryptography>=43
10
+ Requires-Dist: pcrypt
@@ -0,0 +1,279 @@
1
+ splunksecrets - Encrypt and Decrypt Splunk Passwords
2
+ ====================================================
3
+
4
+ |Build Status|
5
+
6
+ ``splunksecrets`` is a tool for working with Splunk secrets offline. It
7
+ currently supports encryption and decryption of passwords, but in the
8
+ future will support offline recursive conversion of a Splunk
9
+ installation from one splunk.secret file to another (e.g. for
10
+ synchronizing splunk.secret across your entire distributed
11
+ infrastructure).
12
+
13
+ Installation
14
+ ------------
15
+
16
+ You can install ``splunksecrets`` using ``uv``:
17
+
18
+ ::
19
+
20
+ uv tool install splunksecrets
21
+
22
+
23
+ Or with pip:
24
+
25
+ ::
26
+
27
+ python -m pip install splunksecrets
28
+
29
+
30
+ Usage
31
+ -----
32
+
33
+ As of version 1.0.0, splunksecrets is broken into subcommands for each
34
+ operaton
35
+
36
+ ::
37
+
38
+ Usage: splunksecrets [OPTIONS] COMMAND [ARGS]...
39
+
40
+ Options:
41
+ --help Show this message and exit.
42
+
43
+ Commands:
44
+ dbconnect-decrypt Decrypt password used for dbconnect identity
45
+ dbconnect-encrypt Encrypt password used for dbconnect identity
46
+ dbconnect-legacy-encrypt Encrypt password used for dbconnect identity using legacy algorithm
47
+ phantom-decrypt Decrypt password used for Phantom asset
48
+ phantom-encrypt Encrypt password used for Phantom asset
49
+ splunk-decrypt Decrypt password using Splunk 7.2 algorithm
50
+ splunk-encrypt Encrypt password using Splunk 7.2 algorithm
51
+ splunk-hash-passwd Generate password hash for use in...
52
+ splunk-legacy-decrypt Decrypt password using legacy Splunk algorithm...
53
+ splunk-legacy-encrypt Encrypt password using legacy Splunk algorithm...
54
+
55
+ You can find details of the usage of each subcommand by running the command
56
+ followed by ``--help``.
57
+
58
+ - **dbconnect-encrypt** and **dbconnect-decrypt** are for interacting with
59
+ credentials stored in ``identities.conf`` in splunk_app_db_connect
60
+ - **phantom-encrypt** and **phantom-decrypt** are for interacting with
61
+ credentials stored in the Phantom database
62
+ - **splunk-encrypt** and **splunk-decrypt** are for interacting with
63
+ credentials from Splunk 7.2 or newer
64
+ - **splunk-legacy-encrypt** and **splunk-legacy-decrypt** are for interacting
65
+ with credentials from Splunk versions below 7.2
66
+ - **splunk-hash-passwd** is for generating Splunk local user password hashes
67
+ for use in ``$SPLUNK_HOME/etc/passwd``
68
+
69
+ Encryption Schemes
70
+ ------------------
71
+
72
+ Splunk passwd hashes
73
+ ~~~~~~~~~~~~~~~~~~~~
74
+
75
+ Splunk password hashes are not, strictly speaking, encrypted. They're
76
+ hashed using the standard Unix ``crypt`` function. The ``$6$`` indicates
77
+ that SHA-512 hashing algorithm is used. Details on SHA-crypt can be
78
+ found `here <https://akkadia.org/drepper/SHA-crypt.txt>`__.
79
+
80
+ Splunk pre-7.2
81
+ ~~~~~~~~~~~~~~
82
+
83
+ Splunk prior to 7.2 used RC4 encryption for secrets, indicated in
84
+ configuration files by ``$1$`` in the encrypted password. The plaintext
85
+ password is XOR'ed with a static salt (``DEFAULTSA``) and then RC4
86
+ encrypted using the first 16-bytes of ``splunk.secret`` as the key. The
87
+ resulting ciphertext is base64-encoded and prepended with ``$1$`` to
88
+ produce the encrypted password seen in the configuration files.
89
+
90
+ Splunk 7.2
91
+ ~~~~~~~~~~
92
+
93
+ Starting in Splunk 7.2, AES256-GCM is used for encryption of secrets,
94
+ indicated in configuration files by ``$7$`` in the encrypted password.
95
+ The ``PBKDF2`` algorithm is used to derive an encryption key from all
96
+ 254 bytes of ``splunk.secret`` (the newline character is stripped from
97
+ the end of the file), using a static salt of ``disk-encryption`` and a
98
+ single iteration. This 256-bit key is then used as the encryption key
99
+ for AES256-GCM, with a 16-byte randomly generated initialization vector.
100
+ The encryption produces both the ciphertext as well as a "tag" that is
101
+ used as part of integrity verification. The iv, ciphertext, and tag (in
102
+ that order) are concatenated, base64-encoded, and prepended with ``$7$``
103
+ to produce the encrypted password seen in the configuration files. If
104
+ the key is less than 254-bytes it is padded with null bytes.
105
+
106
+ Phantom
107
+ ~~~~~~~
108
+
109
+ Phantom stores encrypted credentials in it's internal database as part
110
+ of the JSON blob in the ``configuration`` column of the asset table.
111
+ These credentials are encrypted using AES256-CBC and are stored
112
+ base64-encoded. A SHA256 hash is generated using the public modulus of
113
+ the Phantom RSA private key (located at
114
+ ``/opt/phantom/keystore/private_key.pem``) concatenated with the
115
+ Django ``SECRET_KEY`` (found in
116
+ ``/opt/phantom/www/phantom_ui/secret_key.py``) - this hash is used as
117
+ the key for the AES encryption. A SHA1 hash is generated using the
118
+ ``id`` of the asset from the ``asset`` table - this hash is used as
119
+ the initialization vector (``iv``) for the AES encryption. The password
120
+ to be encrypted is padded using PKCS7 padding prior to encryption.
121
+
122
+ DBConnect pre ~3.12
123
+ ~~~~~~~~~
124
+
125
+ DBConnect used to encrypt passwords using the OpenSSL ``aes-256-cbc`` command.
126
+ This changed somewhere around 3.12 though I haven't bothered to find the exact
127
+ version where the change was made.
128
+ This encryption is fairly straightforward, and is documented in
129
+ ``dbxcrypto.py`` included with DBConnect. The key and IV are derived from
130
+ the secret (stored in ``$SPLUNK_HOMEetc/apps/splunk_app_db_connect/certs/identity.dat``)
131
+ and the salt (randomly generated by OpenSSL). The resulting ciphertext is
132
+ concatenated together with the salt (``Salted__`` + salt + ciphertext) and
133
+ encoded using Base64. The password to be encrypted is padded using PKCS7
134
+ padding prior to encryption.
135
+
136
+ DBConnect post ~3.12
137
+ ~~~~~~~~~~~~~~~~~~~~
138
+
139
+ DBConnect now encrypts passwords using AES GCM with no padding.
140
+ A random 16-byte salt is generated as well as a random 12-byte IV. The key is derived
141
+ from the salt and the secret (stored in ``$SPLUNK_HOMEetc/apps/splunk_app_db_connect/certs/identity.dat``)
142
+ using Scrypt. The final output is ``salt`` + ``iv`` + ``ciphertext``.
143
+
144
+ Known Issues
145
+ ------------
146
+
147
+ - If the splunk secret and an encrypted password don't match, one of
148
+ two things will happen - either you'll get gibberish output, or a
149
+ Python traceback. At some point, we'll hopefully have better error
150
+ checking for this.
151
+ - DBConnect will occassionally store the ending newline from OpenSSL output in
152
+ identities.conf, represented as a single ``\`` at the end of a line. This
153
+ must be removed prior to passing encrypted passwords to ``splunksecrets``
154
+
155
+ Version History
156
+ ---------------
157
+ Version 1.1.0 (2025-06-05)
158
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
159
+ - Added support for encryption/decryption of DBConnect credentials using newer algorithm
160
+ - Bumps minimum Python version to 3.9
161
+ - Refactored code into multiple files
162
+ - Switched from setup.py to pyproject.toml
163
+ - Removed ``six`` dependency used for Python 2 compatibility
164
+
165
+ Version 1.0.1
166
+ ~~~~~~~~~~~~~~
167
+ - Short secrets are padded in the same way Splunk itself does it. Thanks to
168
+ Matt Anderson for this contribution.
169
+
170
+ Version 1.0.0 (2021-06-07)
171
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
172
+ - Updated CLI command docstrings for proper help output
173
+ - Add initial support for encryption/decrypt of Splunk DBConnect credentials
174
+
175
+ Version 1.0.0rc1 (2021-05-19)
176
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
177
+ - New CLI interface that breaks each operation into its own subcommand
178
+ - CLI interface supports passing path to key files (splunk.secret,
179
+ private_key.pem, and secret_key.py) via arguments, or file contents
180
+ via environment variables
181
+ - Add initial support for encryption/decryption of Phantom asset
182
+ credentials (thanks swoops)
183
+
184
+ Version 0.5.1 (2022-06-29)
185
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
186
+ - Allow passing the splunk secret itself as an environment variable
187
+ ~ provided by chutzimir
188
+
189
+
190
+ Version 0.5.0 (2020-06-23)
191
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
192
+ - Add support for passing a path to splunk.secret, the splunk.secret
193
+ contents, and the password/password hash via environment variables
194
+ (thanks hanswurscht)
195
+ - Added error output when trying to decrypt user passwords
196
+
197
+ Version 0.4.3 (2020-02-17)
198
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
199
+
200
+ - Correct an issue when splunk secret is too long. Splunk handles this
201
+ by truncating splunk.secret to 254 bytes, so we now do the same
202
+ (thanks nbertram)
203
+ - Added error checking in case, somehow, splunk secret is too short.
204
+
205
+ Version 0.4.2 (2019-09-29)
206
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
207
+
208
+ - Add handling for incorrectly padded (but otherwise correct) password
209
+ strings as a convenience (thanks rafrey-his)
210
+
211
+ Version 0.4.1 (2019-09-11)
212
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
213
+
214
+ - Fix an issue in Python 3 when using ``--splunk-secret-text`` (thanks
215
+ Joeboyc2)
216
+
217
+ Version 0.4.0 (2019-03-25)
218
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
219
+
220
+ - Add ``--hash-passwd`` flag for generating Splunk password hashes
221
+
222
+ Version 0.3.1 (2019-02-06)
223
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
224
+
225
+ - Fix bug when a character in the password was the same as the salt
226
+ character
227
+ - Add ``--splunk-secret-text`` and ``--password`` arguments for
228
+ non-interactive use (thanks nadidsky)
229
+
230
+ Version 0.3.0 (2019-01-26)
231
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
232
+
233
+ - Add ``--nosalt`` flag for pre-7.2 passwords that are not salted, such
234
+ as ``sslPassword`` (thanks duckfez)
235
+
236
+ Version 0.2.1 (2018-10-27)
237
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
238
+
239
+ - Cosmetic release to update metadata on PyPI
240
+
241
+ Version 0.2.0 (2018-10-24)
242
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
243
+
244
+ - Add support for Splunk 7.2
245
+
246
+ Version 0.1.0 (2018-10-08)
247
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
248
+
249
+ - Initial release
250
+ - Support Splunk < 7.2
251
+
252
+ License Info
253
+ ------------
254
+
255
+ The MIT License (MIT)
256
+
257
+ Copyright (c) 2025 Hurricane Labs LLC
258
+
259
+ Permission is hereby granted, free of charge, to any person obtaining a
260
+ copy of this software and associated documentation files (the
261
+ "Software"), to deal in the Software without restriction, including
262
+ without limitation the rights to use, copy, modify, merge, publish,
263
+ distribute, sublicense, and/or sell copies of the Software, and to
264
+ permit persons to whom the Software is furnished to do so, subject to
265
+ the following conditions:
266
+
267
+ The above copyright notice and this permission notice shall be included
268
+ in all copies or substantial portions of the Software.
269
+
270
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
271
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
272
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
273
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
274
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
275
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
276
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
277
+
278
+ .. |Build Status| image:: https://github.com/HurricaneLabs/splunksecrets/actions/workflows/tests.yml/badge.svg
279
+ :target: https://github.com/HurricaneLabs/splunksecrets/actions/workflows/tests.yml
@@ -0,0 +1,34 @@
1
+ [project]
2
+ name = "splunksecrets"
3
+ version = "1.1.0"
4
+ description = "Command-line tools for working with secrets for Splunk products"
5
+ requires-python = ">=3.9"
6
+ dependencies = [
7
+ "click>=8.0.0",
8
+ "cryptography>=43",
9
+ "pcrypt"
10
+ ]
11
+ authors = [
12
+ {name = "Steve McMaster"},
13
+ {name = "Cameron Schmidt"},
14
+ ]
15
+ maintainers = [
16
+ {name = "Cameron Schmidt"}
17
+ ]
18
+
19
+ [build-system]
20
+ requires = ["hatchling"]
21
+ build-backend = "hatchling.build"
22
+
23
+ [project.scripts]
24
+ splunksecrets = "splunksecrets.cli:main"
25
+
26
+ [tool.hatch.build.targets.wheel]
27
+ packages = ["splunksecrets"]
28
+
29
+ [dependency-groups]
30
+ dev = [
31
+ "pre-commit>=4.1.0",
32
+ "pytest>=8.3.4",
33
+ "ruff>=0.9.5",
34
+ ]
@@ -0,0 +1,19 @@
1
+ from .dbconnect import decrypt_dbconnect, encrypt_dbconnect, get_key_and_iv
2
+ from .splunk import decrypt, encrypt, encrypt_new
3
+ from .phantom import decrypt_phantom, encrypt_phantom, to_bytes
4
+
5
+ __all__ = [
6
+ "decrypt_dbconnect",
7
+ "encrypt_dbconnect",
8
+ "decrypt_splunk_legacy",
9
+ "decrypt_splunk",
10
+ "encrypt_splunk_legacy",
11
+ "encrypt_splunk",
12
+ "encrypt_new",
13
+ "decrypt",
14
+ "encrypt",
15
+ "get_key_and_iv",
16
+ "decrypt_phantom",
17
+ "encrypt_phantom",
18
+ "to_bytes",
19
+ ]