-
Notifications
You must be signed in to change notification settings - Fork 8
Add rule_type=rsync; Add pcre for file definitions #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
thinksilicon
wants to merge
1
commit into
daethnir:main
Choose a base branch
from
thinksilicon:patch-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -386,12 +386,93 @@ def find_match_scp(self, rule): # pylint: disable-msg=R0911,R0912 | |
| files = rule.get('files') | ||
| if not isinstance(files, list): | ||
| files = [files] | ||
| if filepath not in files: | ||
| if rule.get('pcre_match'): | ||
| for file_pattern in files: | ||
| if re.search( file_pattern, filepath ): | ||
| # Allow it! | ||
| return {'command': self.original_command_list} | ||
| self.log( | ||
| 'scp denied - file "{}" - not in approved ' | ||
| 'list {}\n'.format(filepath, files) | ||
| 'regex {}\n'.format( filepath, files ) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Additional needs:
|
||
| ) | ||
| return | ||
| else: | ||
| if filepath not in files: | ||
| self.log( | ||
| 'scp denied - file "{}" - not in approved ' | ||
| 'list {}\n'.format(filepath, files) | ||
| ) | ||
| return | ||
|
|
||
| # Allow it! | ||
| return {'command': self.original_command_list} | ||
|
|
||
| def find_match_rsync( self, rule ): | ||
| """Handle rsync commands""" | ||
|
|
||
| orig_list = [] | ||
| orig_list.extend(self.original_command_list) | ||
| binary = orig_list.pop(0) | ||
| allowed_binaries = ['rsync', '/usr/bin/rsync'] | ||
| if binary not in allowed_binaries: | ||
| self.logdebug( | ||
| 'skipping scp processing - binary "{}" ' | ||
| 'not in approved list.\n'.format(binary) | ||
| ) | ||
| return | ||
|
|
||
| filepaths = [] | ||
| while len( orig_list ) > 0: | ||
| path = orig_list.pop() | ||
| if path == ".": | ||
| break | ||
| filepaths.append( path ) | ||
|
|
||
| arguments = orig_list | ||
|
|
||
| if '--server' not in arguments: | ||
| self.log( | ||
| 'rsync denied - not in server mode.\n' | ||
| ) | ||
| return | ||
|
|
||
| if '--sender' in arguments: | ||
| if not rule.get( 'allow_download' ): | ||
| self.log( | ||
| 'rsync denied - downloading forbidden.\n' | ||
| ) | ||
| return | ||
| else: | ||
| if not rule.get( 'allow_upload' ): | ||
| self.log( | ||
| 'rsync denied - uploading forbidden.\n' | ||
| ) | ||
| return | ||
|
|
||
| if rule.get('files'): | ||
| files = rule.get('files') | ||
| if not isinstance(files, list): | ||
| files = [files] | ||
| if rule.get('pcre_match'): | ||
| for filepath in filepaths: | ||
| cnt = 0 | ||
| for file_pattern in files: | ||
| if re.search( file_pattern, filepath ): | ||
| cnt++ | ||
| if cnt == 0: | ||
| self.log( | ||
| 'rsync denied - file "{}" - not in approved ' | ||
| 'regex {}\n'.format( filepath, files ) | ||
| ) | ||
| return | ||
| else: | ||
| for filepath in filepaths: | ||
| if filepath not in files: | ||
| self.log( | ||
| 'rsync denied - file "{}" - not in approved ' | ||
| 'list {}\n'.format(filepath, files) | ||
| ) | ||
| return | ||
|
|
||
| # Allow it! | ||
| return {'command': self.original_command_list} | ||
|
|
@@ -457,6 +538,8 @@ def find_match(self): | |
| sub = self.find_match_command | ||
| elif rule_type == 'scp': | ||
| sub = self.find_match_scp | ||
| elif rule_type == 'rsync': | ||
| sub = self.find_match_rsync | ||
| else: | ||
| self.log( | ||
| 'fatal: no such rule_type "{}"\n'.format(rule_type) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we be more clear that this is a pcre against the filename.
Rather than overloading 'files' lets add a new one, path_pcre (this will mirror the path_startswith that came in latest version)
Alternatively, if you don't actually need pcre and glob works then use
path_glob- there is also now glob support in authprogs.py, which is used by rsync.