Skip to content

Commit fefe368

Browse files
committed
Updates:
- Disabled urllib3 warnings - Added timeout=0 on `SplunkVersionControl ChangeDetector Directory` savedsearch - Added some minor comments about `/services/properties/savedsearches/default` (no changes in this version) - Updated various internal calls to use sslVerify setting. Hopefully nothing will break but this will result in more SSL verification in various parts of the code Library updates: - Updated Splunk python SDK to 1.7.3
1 parent e0a1d64 commit fefe368

13 files changed

+170
-89
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,26 @@ To do this you will need to install Version Control For SplunkCloud on your Splu
314314

315315
[SplunkVersionControlCloud github](https://github.com/gjanders/SplunkVersionControlCloud)
316316

317+
## How does this compare with other version control apps for Splunk?
318+
As of October 2022, there are still no signs of version control within the Splunk Enterprise (or cloud) product, however you do have a few options in terms of a version control app, these include:
319+
- [Git Version Control for Splunk](https://splunkbase.splunk.com/app/4182) - this app provides a modular input to help with getting configuration into a git repository from the filesystem. Note: on-prem instances only, no Splunk Cloud support.
320+
- [FN1315 - Cover Your Assets: Protect Your Knowledge Objects from Yourself (and Others) - A Paychex story github](https://github.com/paychex/Splunk.Conf19) - this git location provides a list of searches that produce curl commands you can use to restore objects. This can work on-prem or in Splunk Cloud
321+
- [Splunk2Git](https://github.com/paychex/splunk-python/tree/main/Splunk2Git) - Paychex's script to move Splunk knowledge objects into git using REST API
322+
- [Version Control for Splunk (this app)](https://splunkbase.splunk.com/app/4355) - this app uses the REST API to download configuration and store inside a git repository in JSON format. Supports restoration of objects via dashboard (no admin support required). This can work on-prem or on Splunk Cloud remotely (this app runs on prem)
323+
- [VersionControl for SplunkCloud](https://splunkbase.splunk.com/app/5061) - these are the dashboards and savedsearches that are installed on the SplunkCloud instance to support the version control app running remotely
324+
- [Search Head Backup](https://splunkbase.splunk.com/app/6438) - backup to an index, works in Splunk Cloud
325+
317326
## Release Notes
327+
### 1.2.10
328+
Updates:
329+
- Disabled urllib3 warnings
330+
- Added timeout=0 on `SplunkVersionControl ChangeDetector Directory` savedsearch
331+
- Added some minor comments about `/services/properties/savedsearches/default` (no changes in this version)
332+
- Updated various internal calls to use sslVerify setting. Hopefully nothing will break but this will result in more SSL verification in various parts of the code
333+
334+
Library updates:
335+
- Updated Splunk python SDK to 1.7.3
336+
318337
### 1.2.9
319338
New features:
320339
- Added wildcard support for restores, so restore a savedsearch of `Test*` will now restore any savedsearch starting with Test, wildcards can be used on any knowledge object

bin/postversioncontrolrestore.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66
import re
77
import logging
88
from logging.config import dictConfig
9+
import urllib3
910

1011
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "lib"))
1112

1213
from splunklib.searchcommands import dispatch, GeneratingCommand, Configuration, Option
1314
from splunklib.searchcommands.validators import Validator, Boolean
1415
from splunklib.binding import HTTPError
1516

17+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
18+
1619
class OrValidator(Validator):
1720
def __init__(self, a, b):
1821
self.a = a

bin/splunkversioncontrol_backup.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import platform
1010
from splunkversioncontrol_backup_class import SplunkVersionControlBackup
1111
from splunkversioncontrol_utility import runOSProcess, get_password
12+
import urllib3
1213

1314
"""
1415
@@ -18,6 +19,8 @@
1819
1920
"""
2021

22+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
23+
2124
#Define the XML scheme for the inputs page
2225
SCHEME = """<scheme>
2326
<title>Splunk Version Control Backup</title>
@@ -313,7 +316,7 @@ def validate_arguments():
313316
srcUsername = val_data['srcUsername']
314317
srcPassword = val_data['srcPassword']
315318
if srcPassword.find("password:") == 0:
316-
srcPassword = get_password(srcPassword[9:], session_key, logger)
319+
srcPassword = get_password(srcPassword[9:], session_key, logger, sslVerify)
317320

318321
proxies = {}
319322
if 'proxy' in val_data:
@@ -322,7 +325,7 @@ def validate_arguments():
322325
start = proxies['https'].find("password:") + 9
323326
end = proxies['https'].find("@")
324327
logger.debug("Attempting to replace proxy=%s by subsituting=%s with a password" % (proxies['https'], proxies['https'][start:end]))
325-
temp_password = get_password(proxies['https'][start:end], session_key, logger)
328+
temp_password = get_password(proxies['https'][start:end], session_key, logger, sslVerify)
326329
proxies['https'] = proxies['https'][0:start-9] + temp_password + proxies['https'][end:]
327330

328331
try:
@@ -346,7 +349,7 @@ def validate_arguments():
346349
start = gitRepoURL.find("password:") + 9
347350
end = gitRepoURL.find("@")
348351
logger.debug("Attempting to replace gitRepoURL=%s by subsituting=%s with a password" % (gitRepoURL, gitRepoURL[start:end]))
349-
git_password = get_password(gitRepoURL[start:end], session_key, logger)
352+
git_password = get_password(gitRepoURL[start:end], session_key, logger, sslVerify)
350353
gitRepoURL = gitRepoURL[0:start-9] + git_password + gitRepoURL[end:]
351354
else:
352355
gitRepoHTTP = False
@@ -358,7 +361,7 @@ def validate_arguments():
358361
start = git_proxies['https'].find("password:") + 9
359362
end = git_proxies['https'].find("@")
360363
logger.debug("Attempting to replace git_proxy=%s by subsituting=%s with a password" % (git_proxies['https'], git_proxies['https'][start:end]))
361-
temp_password = get_password(git_proxies['https'][start:end], session_key, logger)
364+
temp_password = get_password(git_proxies['https'][start:end], session_key, logger, sslVerify)
362365
git_proxies['https'] = git_proxies['https'][0:start-9] + temp_password + git_proxies['https'][end:]
363366

364367
if gitRepoHTTP and len(git_proxies) > 0:

bin/splunkversioncontrol_backup_class.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from io import open
1717
import platform
1818
import hashlib
19+
import urllib3
1920
from splunkversioncontrol_utility import runOSProcess, get_password
2021
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "lib"))
2122

@@ -30,6 +31,8 @@
3031
3132
"""
3233

34+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
35+
3336
splunkLogsDir = os.environ['SPLUNK_HOME'] + "/var/log/splunk"
3437
#Setup the logging
3538
logging_config = dict(
@@ -233,6 +236,7 @@ def runQueries(self, app, endpoint, type, fieldIgnoreList, aliasAttributes={}, v
233236
elif innerChild.tag.endswith("content"):
234237

235238
# optimisation to deal with the giant display.visualizations... on savedsearches only
239+
# an improved version of this optimisation may be to use /services/properties/savedsearches/default and to filter out *all* default parameters for searches
236240
skip_visualizations = True
237241

238242
for theAttribute in innerChild[0]:
@@ -374,7 +378,8 @@ def runQueries(self, app, endpoint, type, fieldIgnoreList, aliasAttributes={}, v
374378
if sharing not in infoList:
375379
infoList[sharing] = []
376380

377-
#REST API does not support the creation of null queue entries as tested in 7.0.5 and 7.2.1, these are also unused on search heads anyway so ignoring these with a warning
381+
# REST API does not support the creation of null queue entries as tested in 7.0.5 and 7.2.1, these are also unused on search heads anyway so ignoring these with a warning
382+
# however this might instead work on /services/properties/... or /services/configs/conf-... endpoints, to be tested if the requirement comes up
378383
if type == "fieldtransformations" and "FORMAT" in info and info["FORMAT"] == "nullQueue":
379384
logger.info("i=\"%s\" Dropping the backup of name=\"%s\" of type=%s in app context app=%s with owner=%s because nullQueue entries cannot be created via REST API (and they are not required in search heads)" % (self.stanzaName, info["name"], type, app, info["owner"]))
380385
else:
@@ -949,7 +954,7 @@ def dashboards(self, app):
949954
###########################
950955
def savedsearches(self, app):
951956
ignoreList = [ "embed.enabled", "triggered_alert_count", "next_scheduled_time", "qualifiedSearch" ]
952-
957+
# TODO /services/properties/savedsearches/default could be used to further filter out "default" values going into the git backup
953958
return self.runQueries(app, "/saved/searches", "savedsearches", ignoreList, extra_args="&listDefaultActionArgs=false")
954959

955960
###########################
@@ -1437,6 +1442,17 @@ def run_script(self):
14371442

14381443
self.session_key = config['session_key']
14391444

1445+
if 'sslVerify' in config:
1446+
if config['sslVerify'].lower() == 'true' or config['sslVerify'] == "1":
1447+
self.sslVerify = True
1448+
logger.debug('sslverify set to boolean True from: ' + config['sslVerify'])
1449+
elif config['sslVerify'].lower() == 'false' or config['sslVerify'] == "0":
1450+
self.sslVerify = False
1451+
logger.debug('sslverify set to boolean False from: ' + config['sslVerify'])
1452+
else:
1453+
self.sslVerify = config['sslVerify']
1454+
logger.debug('sslverify set to: ' + config['sslVerify'])
1455+
14401456
self.git_password = False
14411457
# a flag for a http/https vs SSH based git repo
14421458
if self.gitRepoURL.find("http") == 0:
@@ -1446,7 +1462,7 @@ def run_script(self):
14461462
start = self.gitRepoURL.find("password:") + 9
14471463
end = self.gitRepoURL.find("@")
14481464
logger.debug("Attempting to replace self.gitRepoURL=%s by subsituting=%s with a password" % (self.gitRepoURL, self.gitRepoURL[start:end]))
1449-
self.git_password = get_password(self.gitRepoURL[start:end], self.session_key, logger)
1465+
self.git_password = get_password(self.gitRepoURL[start:end], self.session_key, logger, self.sslVerify)
14501466
self.gitRepoURL = self.gitRepoURL[0:start-9] + self.git_password + self.gitRepoURL[end:]
14511467
else:
14521468
self.gitRepoURL_logsafe = self.gitRepoURL
@@ -1495,7 +1511,7 @@ def run_script(self):
14951511
start = proxies['https'].find("password:") + 9
14961512
end = proxies['https'].find("@")
14971513
logger.debug("Attempting to replace proxy=%s by subsituting=%s with a password" % (proxies['https'], proxies['https'][start:end]))
1498-
temp_password = get_password(proxies['https'][start:end], self.session_key, logger)
1514+
temp_password = get_password(proxies['https'][start:end], self.session_key, logger, self.sslVerify)
14991515
proxies['https'] = proxies['https'][0:start-9] + temp_password + proxies['https'][end:]
15001516

15011517
self.proxies = proxies
@@ -1507,22 +1523,11 @@ def run_script(self):
15071523
start = git_proxies['https'].find("password:") + 9
15081524
end = git_proxies['https'].find("@")
15091525
logger.debug("Attempting to replace git_proxy=%s by subsituting=%s with a password" % (git_proxies['https'], git_proxies['https'][start:end]))
1510-
temp_password = get_password(git_proxies['https'][start:end], self.session_key, logger)
1526+
temp_password = get_password(git_proxies['https'][start:end], self.session_key, logger, self.sslVerify)
15111527
git_proxies['https'] = git_proxies['https'][0:start-9] + temp_password + git_proxies['https'][end:]
15121528

15131529
self.git_proxies = git_proxies
15141530

1515-
if 'sslVerify' in config:
1516-
if config['sslVerify'].lower() == 'true' or config['sslVerify'] == "1":
1517-
self.sslVerify = True
1518-
logger.debug('sslverify set to boolean True from: ' + config['sslVerify'])
1519-
elif config['sslVerify'].lower() == 'false' or config['sslVerify'] == "0":
1520-
self.sslVerify = False
1521-
logger.debug('sslverify set to boolean False from: ' + config['sslVerify'])
1522-
else:
1523-
self.sslVerify = config['sslVerify']
1524-
logger.debug('sslverify set to: ' + config['sslVerify'])
1525-
15261531
self.file_per_ko = False
15271532
if 'file_per_ko' in config:
15281533
if config['file_per_ko'].lower() == 'true' or config['file_per_ko'] == "1":
@@ -1552,7 +1557,7 @@ def run_script(self):
15521557
headers={'Authorization': 'Splunk %s' % config['session_key']}
15531558

15541559
url = 'https://localhost:8089/services/shcluster/captain/info?output_mode=json'
1555-
res = requests.get(url, headers=headers, verify=False)
1560+
res = requests.get(url, headers=headers, verify=self.sslVerify)
15561561
if (res.status_code == 503):
15571562
logger.debug("i=\"%s\" Non-shcluster / standalone instance, safe to run on this node" % (self.stanzaName))
15581563
elif (res.status_code != requests.codes.ok):
@@ -1567,7 +1572,7 @@ def run_script(self):
15671572
logger.info("i=\"%s\" we are on the captain node, running" % (self.stanzaName))
15681573

15691574
if not useLocalAuth and self.srcPassword.find("password:") == 0:
1570-
self.srcPassword = get_password(self.srcPassword[9:], self.session_key, logger)
1575+
self.srcPassword = get_password(self.srcPassword[9:], self.session_key, logger, self.sslVerify)
15711576

15721577
if 'appsList' in config and config['appsList']!="":
15731578
appList = [app.strip() for app in config['appsList'].split(',')]
@@ -1876,7 +1881,7 @@ def run_script(self):
18761881
if len(self.git_proxies) > 0 and self.gitRepoHTTP:
18771882
push_str = "export HTTPS_PROXY=" + self.git_proxies["https"] + " ; " + push_str
18781883
(output, stderrout, res) = runOSProcess(push_str, logger, timeout=300, shell=True)
1879-
res=True
1884+
#res=True
18801885
if res == False:
18811886
if not self.show_passwords and self.git_password:
18821887
output = output.replace(self.git_password, "password_removed")

0 commit comments

Comments
 (0)