Skip to content

Commit fd00ab7

Browse files
mgr/smb: add password filter support to ceph smb apply command
The apply command both takes passwords in the input and can display them in the results. Add two options --password-filter and --password-filter-out that control how these passwords are filtered. If --password-filter is given but --password-filter-out is not, the output value is assumed to be the same as the input. So for example you could run `ceph smb apply -i /file --password-filter=base64` which would assume the password values in the input are base64 encoded and then the results would include the same values. `ceph smb apply -i /file --password-filter-out=hidden` would take a file with unobscured passwords but emit results with passwords hidden. Signed-off-by: John Mulligan <[email protected]>
1 parent 32c2441 commit fd00ab7

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

src/pybind/mgr/smb/module.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
)
2121
from .enums import (
2222
AuthMode,
23+
InputPasswordFilter,
2324
JoinSourceType,
2425
PasswordFilter,
2526
ShowResults,
@@ -141,13 +142,46 @@ def internal_store_backend(self) -> str:
141142
self.get_module_option('internal_store_backend', ''),
142143
)
143144

145+
def _apply_res(
146+
self,
147+
resource_input: List[resources.SMBResource],
148+
password_filter: InputPasswordFilter = InputPasswordFilter.NONE,
149+
password_filter_out: Optional[PasswordFilter] = None,
150+
) -> results.ResultGroup:
151+
in_pf = password_filter.to_password_filter() # update enum type
152+
# use the same filtering as the input unless expliclitly set
153+
out_pf = password_filter_out if password_filter_out else in_pf
154+
if in_pf is not PasswordFilter.NONE:
155+
in_op = (in_pf, PasswordFilter.NONE)
156+
log.debug('Password filtering for resource apply: %r', in_op)
157+
resource_input = [r.convert(in_op) for r in resource_input]
158+
all_results = self._handler.apply(resource_input)
159+
if out_pf is not PasswordFilter.NONE:
160+
# we need to apply the conversion filter to the output
161+
# resources in the results - otherwise we would show raw
162+
# passwords - this will be the inverse of the filter applied to
163+
# the input
164+
out_op = (PasswordFilter.NONE, out_pf)
165+
log.debug('Password filtering for smb apply output: %r', in_op)
166+
all_results = all_results.convert_results(out_op)
167+
return all_results
168+
144169
@cli.SMBCommand('apply', perm='rw')
145-
def apply_resources(self, inbuf: str) -> results.ResultGroup:
170+
def apply_resources(
171+
self,
172+
inbuf: str,
173+
password_filter: InputPasswordFilter = InputPasswordFilter.NONE,
174+
password_filter_out: Optional[PasswordFilter] = None,
175+
) -> results.ResultGroup:
146176
"""Create, update, or remove smb configuration resources based on YAML
147177
or JSON specs
148178
"""
149179
try:
150-
return self._handler.apply(resources.load_text(inbuf))
180+
return self._apply_res(
181+
resources.load_text(inbuf),
182+
password_filter=password_filter,
183+
password_filter_out=password_filter_out,
184+
)
151185
except resources.InvalidResourceError as err:
152186
# convert the exception into a result and return it as the only
153187
# item in the result group

0 commit comments

Comments
 (0)