Skip to content

Commit 9c2c423

Browse files
committed
IdP: extend ${u} with syntax to exclude by group
just like before, if vpath contains ${u} then the IdP-volume is created unconditionally but this is new: ${u%+foo} creates the vol only if user is member of group foo ${u%-foo} creates the vol if user is NOT member of group foo
1 parent 999789c commit 9c2c423

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

copyparty/authsrv.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272
BAD_CFG = "invalid config; {}".format(SEE_LOG)
7373
SBADCFG = " ({})".format(BAD_CFG)
7474

75+
PTN_U_GRP = re.compile(r"\$\{u%([+-])([^}]+)\}")
76+
7577

7678
class CfgEx(Exception):
7779
pass
@@ -953,12 +955,24 @@ def _map_volume_idp(
953955
un_gn = [("", "")]
954956

955957
for un, gn in un_gn:
958+
m = PTN_U_GRP.search(dst0)
959+
if m:
960+
req, gnc = m.groups()
961+
hit = gnc in (un_gns.get(un) or [])
962+
if req == "+":
963+
if not hit:
964+
continue
965+
elif hit:
966+
continue
967+
956968
# if ap/vp has a user/group placeholder, make sure to keep
957969
# track so the same user/group is mapped when setting perms;
958970
# otherwise clear un/gn to indicate it's a regular volume
959971

960972
src1 = src0.replace("${u}", un or "\n")
961973
dst1 = dst0.replace("${u}", un or "\n")
974+
src1 = PTN_U_GRP.sub(un or "\n", src1)
975+
dst1 = PTN_U_GRP.sub(un or "\n", dst1)
962976
if src0 == src1 and dst0 == dst1:
963977
un = ""
964978

@@ -2312,7 +2326,7 @@ def _reload(self, verbosity: int = 9) -> None:
23122326
idp_vn, _ = vfs.get(idp_vp, "*", False, False)
23132327
idp_vp0 = idp_vn.vpath0
23142328

2315-
sigils = set(re.findall(r"(\${[ug]})", idp_vp0))
2329+
sigils = set(re.findall(r"(\${[ug][}%])", idp_vp0))
23162330
if len(sigils) > 1:
23172331
t = '\nWARNING: IdP-volume "/%s" created by "/%s" has multiple IdP placeholders: %s'
23182332
self.idp_warn.append(t % (idp_vp, idp_vp0, list(sigils)))
@@ -2344,7 +2358,7 @@ def _reload(self, verbosity: int = 9) -> None:
23442358
elif oth_write:
23452359
taxs = "WRITABLE BY %r" % (oth_write,)
23462360
else:
2347-
continue
2361+
break # no sigil; not idp; safe to stop
23482362

23492363
t = '\nWARNING: IdP-volume "/%s" created by "/%s" has parent/grandparent "/%s" and would be %s'
23502364
self.idp_err.append(t % (idp_vp, idp_vp0, par_vn.vpath, taxs))

docs/examples/docker/idp/copyparty.conf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# because that is the data-volume in the docker containers,
1414
# because a deployment like this (with an IdP) is more commonly
1515
# seen in containerized environments -- but this is not required
16+
#
17+
# the example group "su" (super-user) is the admins group
1618

1719

1820
[global]
@@ -78,6 +80,18 @@
7880
rwmda: @${g}, @su # read-write-move-delete-admin for that group + the "su" group
7981

8082

83+
[/sus/${u%+su}] # users which ARE members of group "su" gets /sus/username
84+
/w/tank1/${u} # which will be "tank1/username" in the docker data volume
85+
accs:
86+
rwmda: ${u} # read-write-move-delete-admin for that username
87+
88+
89+
[/m8s/${u%-su}] # users which are NOT members of group "su" gets /m8s/username
90+
/w/tank2/${u} # which will be "tank2/username" in the docker data volume
91+
accs:
92+
rwmda: ${u} # read-write-move-delete-admin for that username
93+
94+
8195
# and create some strategic volumes to prevent anyone from gaining
8296
# unintended access to priv folders if the users/groups db is lost
8397
[/u]
@@ -88,3 +102,7 @@
88102
/w/lounge
89103
accs:
90104
rwmda: @su
105+
[/sus]
106+
/w/tank1
107+
[/m8s]
108+
/w/tank2

0 commit comments

Comments
 (0)