Skip to content

Commit 6aabb8b

Browse files
committed
New option disable_git_ssl_verify
Support for password: syntax for the gitRepoURL parameter when using http/https Bugfix for proxy code to work with git & HTTP proxies
1 parent ce9549e commit 6aabb8b

8 files changed

+153
-39
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,14 @@ To do this you will need to install Version Control For SplunkCloud on your Splu
288288

289289
[SplunkVersionControlCloud github](https://github.com/gjanders/SplunkVersionControlCloud)
290290

291-
## Release Notes
291+
## Release Notes
292+
### 1.2.3
293+
New option `disable_git_ssl_verify`
294+
295+
Support for password: syntax for the gitRepoURL parameter when using http/https
296+
297+
Bugfix for proxy code to work with git & HTTP proxies
298+
292299
### 1.2.2
293300
This version includes a few changes, these include two new parameters on the version control backup:
294301
`run_ko_query` - if enabled this runs a Splunk savedsearch and adds the additional information of tag=`git_tag_name` into the output of the modular input which is then indexed

README/inputs.conf.spec

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ srcPassword = <value>
88
gitTempDir = <value>
99
* location where to store the output of the script on the filesystem (note this directory will be deleted/re-created but the parent dir must exist)
1010
gitRepoURL = <value>
11-
* git repository URL to store the objects
11+
* git repository URL to store the objects. password:passwordinpasswordsconf can be used for token/password substitution if required for http/https URL's
1212
sslVerify = <boolean>
1313
* Set to 'true' or 'false' to enable/disable SSL verification for REST requests to `srcUrl`. Set to a path to specify a file with valid CA. (https://2.python-requests.org/en/master/user/advanced/#ssl-cert-verification)
1414
noPrivate = <boolean>
@@ -51,6 +51,8 @@ run_ko_query = <boolean>
5151
* Do you want to run a Splunk query to determine which knowledge objects changed? macro 'splunk_vc_ko_query' (defaults to false)
5252
run_ko_diff = <boolean>
5353
* Should output of the modular input include diff information (requires run_ko_query to be true, defaults to false)
54+
disable_git_ssl_verify = <boolean>
55+
* Use GIT_SSL_NO_VERIFY=true on all git commands
5456

5557
[splunkversioncontrol_restore://<name>]
5658
destURL = <value>
@@ -62,7 +64,7 @@ destPassword = <value>
6264
gitTempDir = <value>
6365
* location where to store the output of the script on the filesystem (note this directory will be deleted/re-created but the parent dir must exist)
6466
gitRepoURL = <value>
65-
* git repository URL to restore the objects from
67+
* git repository URL to restore the objects from. password:passwordinpasswordsconf can be used for token/password substitution if required for http/https URL's
6668
sslVerify = <boolean>
6769
* Set to 'true' or 'false' to enable/disable SSL verification for REST requests to `srcUrl`. Set to a path to specify a file with valid CA. (https://2.python-requests.org/en/master/user/advanced/#ssl-cert-verification)
6870
auditLogsLookupBackTime = <value>
@@ -87,3 +89,6 @@ git_proxy = <value>
8789
* If supplied provides a proxy setting to use to access the git repository (https proxy). Use https://user:password:[email protected]:3128 and the application will obtain the password for the entry 'passwordinpasswordsconf'. If password: is not used the password is used as per a normal proxy setting, for example https://user:[email protected]:3128</description>
8890
file_per_ko = <boolean>
8991
* Do you want one file per knowledge object? Or a combined file? Defaults to false (i.e. 1 large file for global dashboards in an app). Note that if you change this you will need to re-create or wipe the repository as the files are stored differently...Note this setting should match in both backup and restore modular inputs for a particular repo
92+
disable_git_ssl_verify = <boolean>
93+
* Use GIT_SSL_NO_VERIFY=true on all git commands
94+

bin/splunkversioncontrol_backup.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
</arg>
4747
<arg name="gitRepoURL">
4848
<title>gitRepoURL</title>
49-
<description>git repository URL to store the objects</description>
49+
<description>git repository URL to store the objects. password:passwordinpasswordsconf can be used for token/password substitution if required for http/https URL's</description>
5050
</arg>
5151
<arg name="sslVerify">
5252
<title>sslVerify</title>
@@ -167,6 +167,13 @@
167167
<data_type>boolean</data_type>
168168
<validation>is_bool('run_ko_diff')</validation>
169169
</arg>
170+
<arg name="disable_git_ssl_verify">
171+
<title>disable_git_ssl_verify</title>
172+
<description>Use GIT_SSL_NO_VERIFY=true on all git commands</description>
173+
<required_on_create>false</required_on_create>
174+
<data_type>boolean</data_type>
175+
<validation>is_bool('disable_git_ssl_verify')</validation>
176+
</arg>
170177
</args>
171178
</endpoint>
172179
</scheme>
@@ -256,6 +263,17 @@ def validate_arguments():
256263
else:
257264
ssh_command = "ssh"
258265

266+
disable_git_ssl_verify = False
267+
if 'disable_git_ssl_verify' in val_data:
268+
if val_data['disable_git_ssl_verify'].lower() == 'true' or val_data['disable_git_ssl_verify'] == "1":
269+
git_command = "GIT_SSL_NO_VERIFY=true " + git_command
270+
logger.debug('git_command now has GIT_SSL_NO_VERIFY=true because disable_git_ssl_verify: ' + val_data['disable_git_ssl_verify'])
271+
disable_git_ssl_verify = True
272+
elif val_data['disable_git_ssl_verify'].lower() == 'false' or val_data['disable_git_ssl_verify'] == "0":
273+
logger.debug('disable_git_ssl_verify set to boolean False from: ' + val_data['disable_git_ssl_verify'])
274+
else:
275+
logger.warn('disable_git_ssl_verify not set to a valid value, ignoring the setting, please update the setting from: ' + val_data['disable_git_ssl_verify'])
276+
259277
sslVerify = False
260278
if 'sslVerify' in val_data:
261279
if val_data['sslVerify'].lower() == 'true' or val_data['sslVerify'] == "1":
@@ -302,6 +320,12 @@ def validate_arguments():
302320
proxy_command = ""
303321
if gitRepoURL.find("http") == 0:
304322
gitRepoHTTP = True
323+
if gitRepoURL.find("password:") != -1:
324+
start = gitRepoURL.find("password:") + 9
325+
end = gitRepoURL.find("@")
326+
logger.debug("Attempting to replace gitRepoURL=%s by subsituting=%s with a password" % (gitRepoURL, gitRepoURL[start:end]))
327+
temp_password = get_password(gitRepoURL[start:end], session_key, logger)
328+
gitRepoURL = gitRepoURL[0:start-9] + temp_password + gitRepoURL[end:]
305329
else:
306330
gitRepoHTTP = False
307331

@@ -335,7 +359,6 @@ def validate_arguments():
335359
logger.error("Failed to validate the git repo URL, stdout of '%s', stderr of '%s'" % (stdout, stderr))
336360
sys.exit(6)
337361

338-
339362
#Print the scheme
340363
def do_scheme():
341364
print(SCHEME)

bin/splunkversioncontrol_backup_class.py

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,11 +1322,23 @@ def run_script(self):
13221322

13231323
self.gitRepoURL = config['gitRepoURL']
13241324

1325+
self.session_key = config['session_key']
1326+
13251327
# a flag for a http/https vs SSH based git repo
13261328
if self.gitRepoURL.find("http") == 0:
13271329
self.gitRepoHTTP = True
1330+
if self.gitRepoURL.find("password:") != -1:
1331+
self.gitRepoURL_logsafe = self.gitRepoURL
1332+
start = self.gitRepoURL.find("password:") + 9
1333+
end = self.gitRepoURL.find("@")
1334+
logger.debug("Attempting to replace self.gitRepoURL=%s by subsituting=%s with a password" % (self.gitRepoURL, self.gitRepoURL[start:end]))
1335+
temp_password = get_password(self.gitRepoURL[start:end], self.session_key, logger)
1336+
self.gitRepoURL = self.gitRepoURL[0:start-9] + temp_password + self.gitRepoURL[end:]
1337+
else:
1338+
self.gitRepoURL_logsafe = self.gitRepoURL
13281339
else:
13291340
self.gitRepoHTTP = False
1341+
self.gitRepoURL_logsafe = self.gitRepoURL
13301342

13311343
if 'git_command' in config:
13321344
self.git_command = config['git_command'].strip()
@@ -1335,6 +1347,15 @@ def run_script(self):
13351347
else:
13361348
self.git_command = "git"
13371349

1350+
if 'disable_git_ssl_verify' in config:
1351+
if config['disable_git_ssl_verify'].lower() == 'true' or config['disable_git_ssl_verify'].lower() == 't' or config['disable_git_ssl_verify'] == "1":
1352+
self.git_command = "GIT_SSL_NO_VERIFY=true " + self.git_command
1353+
logger.debug('git_command now has GIT_SSL_NO_VERIFY=true because disable_git_ssl_verify: ' + config['disable_git_ssl_verify'])
1354+
elif config['disable_git_ssl_verify'].lower() == 'false' or config['disable_git_ssl_verify'] == "0":
1355+
logger.debug('disable_git_ssl_verify set to boolean False from: ' + config['disable_git_ssl_verify'])
1356+
else:
1357+
logger.warn('disable_git_ssl_verify not set to a valid value, ignoring the setting, please update the setting from: ' + config['disable_git_ssl_verify'])
1358+
13381359
if 'ssh_command' in config:
13391360
self.ssh_command = config['ssh_command'].strip()
13401361
self.ssh_command = self.ssh_command.replace("\\","/")
@@ -1360,7 +1381,7 @@ def run_script(self):
13601381
start = proxies['https'].find("password:") + 9
13611382
end = proxies['https'].find("@")
13621383
logger.debug("Attempting to replace proxy=%s by subsituting=%s with a password" % (proxies['https'], proxies['https'][start:end]))
1363-
temp_password = get_password(proxies['https'][start:end], session_key, logger)
1384+
temp_password = get_password(proxies['https'][start:end], self.session_key, logger)
13641385
proxies['https'] = proxies['https'][0:start-9] + temp_password + proxies['https'][end:]
13651386

13661387
self.proxies = proxies
@@ -1372,7 +1393,7 @@ def run_script(self):
13721393
start = git_proxies['https'].find("password:") + 9
13731394
end = git_proxies['https'].find("@")
13741395
logger.debug("Attempting to replace git_proxy=%s by subsituting=%s with a password" % (git_proxies['https'], git_proxies['https'][start:end]))
1375-
temp_password = get_password(git_proxies['https'][start:end], session_key, logger)
1396+
temp_password = get_password(git_proxies['https'][start:end], self.session_key, logger)
13761397
git_proxies['https'] = git_proxies['https'][0:start-9] + temp_password + git_proxies['https'][end:]
13771398

13781399
self.git_proxies = git_proxies
@@ -1407,7 +1428,6 @@ def run_script(self):
14071428
#Use current epoch to output a checkpoint file at the end
14081429
#If we have not run before just backup everything
14091430
currentEpochTime = calendar.timegm(time.gmtime())
1410-
self.session_key = config['session_key']
14111431

14121432
headers={'Authorization': 'Splunk %s' % config['session_key']}
14131433

@@ -1461,10 +1481,10 @@ def run_script(self):
14611481

14621482
(output, stderrout, res) = self.clone_git_dir(config)
14631483
if res == False:
1464-
logger.fatal("i=\"%s\" git clone failed for some reason...on url %s stdout of '%s' with stderrout of '%s'" % (self.stanzaName, self.gitRepoURL, output, stderrout))
1484+
logger.fatal("i=\"%s\" git clone failed for some reason...on url %s stdout of '%s' with stderrout of '%s'" % (self.stanzaName, self.gitRepoURL_logsafe, output, stderrout))
14651485
sys.exit(1)
14661486
else:
1467-
logger.info("i=\"%s\" Successfully cloned the git URL from %s into directory %s" % (self.stanzaName, self.gitRepoURL, self.gitTempDir))
1487+
logger.info("i=\"%s\" Successfully cloned the git URL from %s into directory %s" % (self.stanzaName, self.gitRepoURL_logsafe, self.gitTempDir))
14681488
if not ".git" in os.listdir(self.gitTempDir):
14691489
#include the subdirectory which is the git repo
14701490
self.gitTempDir = self.gitTempDir + "/" + os.listdir(self.gitTempDir)[0]
@@ -1542,10 +1562,10 @@ def run_script(self):
15421562

15431563
(output, stderrout, res) = self.clone_git_dir(config)
15441564
if res == False:
1545-
logger.fatal("i=\"%s\" git clone failed for some reason...on url %s stdout of '%s' with stderrout of '%s'" % (self.stanzaName, self.gitRepoURL, output, stderrout))
1565+
logger.fatal("i=\"%s\" git clone failed for some reason...on url %s stdout of '%s' with stderrout of '%s'" % (self.stanzaName, self.gitRepoURL_logsafe, output, stderrout))
15461566
sys.exit(1)
15471567
else:
1548-
logger.info("i=\"%s\" Successfully cloned the git URL from %s into directory %s" % (self.stanzaName, self.gitRepoURL, self.gitTempDir))
1568+
logger.info("i=\"%s\" Successfully cloned the git URL from %s into directory %s" % (self.stanzaName, self.gitRepoURL_logsafe, self.gitTempDir))
15491569

15501570
(output2, stderrout2, res) = self.set_git_details(config)
15511571
if res == False:
@@ -1681,10 +1701,10 @@ def run_script(self):
16811701

16821702
(output, stderrout, res) = self.clone_git_dir(config)
16831703
if res == False:
1684-
logger.fatal("i=\"%s\" git clone failed for some reason...on url %s stdout of '%s' with stderrout of '%s'" % (self.stanzaName, self.gitRepoURL, output, stderrout))
1704+
logger.fatal("i=\"%s\" git clone failed for some reason...on url %s stdout of '%s' with stderrout of '%s'" % (self.stanzaName, self.gitRepoURL_logsafe, output, stderrout))
16851705
sys.exit(1)
16861706
else:
1687-
logger.info("i=\"%s\" Successfully cloned the git URL from %s into directory %s" % (self.stanzaName, self.gitRepoURL, self.gitTempDir))
1707+
logger.info("i=\"%s\" Successfully cloned the git URL from %s into directory %s" % (self.stanzaName, self.gitRepoURL_logsafe, self.gitTempDir))
16881708

16891709
(output2, stderrout2, res) = self.set_git_details(config)
16901710
if res == False:

bin/splunkversioncontrol_rest_restore.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ def handle_POST(self):
120120
useLocalAuth = json_dict['useLocalAuth']
121121
if isinstance(useLocalAuth, bool) and useLocalAuth:
122122
useLocalAuth = True
123+
elif isinstance(useLocalAuth, bool) and not useLocalAuth:
124+
pass
123125
elif useLocalAuth.lower() == 't' or useLocalAuth.lower() == "true":
124126
useLocalAuth = True
125127
if not useLocalAuth:
@@ -141,7 +143,16 @@ def handle_POST(self):
141143

142144
sslVerify = False
143145
if 'sslVerify' in json_dict:
144-
sslVerify = json_dict['sslVerify']
146+
sslVerifyValue = json_dict['sslVerify']
147+
if sslVerifyValue.lower() == 'true' or sslVerifyValue == "1":
148+
sslVerify = True
149+
logger.debug('sslverify set to boolean True from: ' + sslVerifyValue)
150+
elif sslVerifyValue.lower() == 'false' or sslVerifyValue == "0":
151+
sslVerify = False
152+
logger.debug('sslverify set to boolean False from: ' + sslVerifyValue)
153+
else:
154+
sslVerify = sslVerifyValue
155+
logger.debug('sslverify set to: %s' % (sslVerifyValue))
145156

146157
headers = {}
147158
auth = None

bin/splunkversioncontrol_restore.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
</arg>
4949
<arg name="gitRepoURL">
5050
<title>gitRepoURL</title>
51-
<description>git repository URL to store the objects</description>
51+
<description>git repository URL to store the objects. password:passwordinpasswordsconf can be used for token/password substitution if required for http/https URL's</description>
5252
</arg>
5353
<arg name="sslVerify">
5454
<title>sslVerify</title>
@@ -118,6 +118,13 @@
118118
<data_type>boolean</data_type>
119119
<validation>is_bool('file_per_ko')</validation>
120120
</arg>
121+
<arg name="disable_git_ssl_verify">
122+
<title>disable_git_ssl_verify</title>
123+
<description>Use GIT_SSL_NO_VERIFY=true on all git commands</description>
124+
<required_on_create>false</required_on_create>
125+
<data_type>boolean</data_type>
126+
<validation>is_bool('disable_git_ssl_verify')</validation>
127+
</arg>
121128
</args>
122129
</endpoint>
123130
</scheme>
@@ -262,6 +269,17 @@ def validate_arguments():
262269
else:
263270
ssh_command = "ssh"
264271

272+
disable_git_ssl_verify = False
273+
if 'disable_git_ssl_verify' in val_data:
274+
if val_data['disable_git_ssl_verify'].lower() == 'true' or val_data['disable_git_ssl_verify'] == "1":
275+
git_command = "GIT_SSL_NO_VERIFY=true " + git_command
276+
logger.debug('git_command now has GIT_SSL_NO_VERIFY=true because disable_git_ssl_verify: ' + val_data['disable_git_ssl_verify'])
277+
disable_git_ssl_verify = True
278+
elif val_data['disable_git_ssl_verify'].lower() == 'false' or val_data['disable_git_ssl_verify'] == "0":
279+
logger.debug('disable_git_ssl_verify set to boolean False from: ' + val_data['disable_git_ssl_verify'])
280+
else:
281+
logger.warn('disable_git_ssl_verify not set to a valid value, ignoring the setting, please update the setting from: ' + val_data['disable_git_ssl_verify'])
282+
265283
git_proxies = {}
266284
if 'git_proxy' in val_data:
267285
git_proxies["https"] = val_data['git_proxy']
@@ -274,6 +292,12 @@ def validate_arguments():
274292

275293
if gitRepoURL.find("http") == 0:
276294
gitRepoHTTP = True
295+
if gitRepoURL.find("password:") != -1:
296+
start = gitRepoURL.find("password:") + 9
297+
end = gitRepoURL.find("@")
298+
logger.debug("Attempting to replace gitRepoURL=%s by subsituting=%s with a password" % (gitRepoURL, gitRepoURL[start:end]))
299+
temp_password = get_password(gitRepoURL[start:end], session_key, logger)
300+
gitRepoURL = gitRepoURL[0:start-9] + temp_password + gitRepoURL[end:]
277301
else:
278302
gitRepoHTTP = False
279303

0 commit comments

Comments
 (0)