sudoers 파일에 대한 다중 매개변수 와일드카드 일치?

sudoers 파일에 대한 다중 매개변수 와일드카드 일치?

제한된 매개 변수 집합(일부 선택 사항)을 허용하는 sudoer에서 항목을 만드는 방법을 알아내려고 노력하고 있지만 명령은 여전히 ​​매우 제한적입니다.

이러한 제한을 제한하는 쉬운 방법이 있습니까?

사용자가 -w 플래그와 선택적 값을 사용하여 실행할 수 있지만 여전히 제한되기를 바랍니다. -w 옵션의 값을 하드코딩하고 싶지 않습니다. 사용자는 이러한 명령 중 하나를 실행할 수 있어야 합니다. 여기서 10은 임의의 숫자입니다.

/usr/bin/iptables -nvL *
/usr/bin/iptables -w -nvL *
/usr/bin/iptables -w 10 -nvL *

저는 이 4개의 항목을 생각해냈습니다. 선택적 값을 정의하는 더 좋은 방법이 있습니까?

username ALL=(root) NOPASSWD: /usr/bin/iptables -nvL *
username ALL=(root) NOPASSWD: /usr/bin/iptables -w -nvL *
username ALL=(root) NOPASSWD: /usr/bin/iptables -w [[\:digit\:]] -nvL *
username ALL=(root) NOPASSWD: /usr/bin/iptables -w [[\:digit\:]][[\:digit\:]] -nvL *

답변1

죄송하지만
"?" 또는 "*"와 같은 와일드카드를 사용하지 않으려면 원하는 내용을 매우 정확하게 제공해야 합니다.

sudoers 매뉴얼 페이지에 따르면 범용 와일드카드만 제공합니다.

Wildcards
  sudo allows shell-style wildcards (aka meta or glob characters) to be used in host names,
  path names and command line arguments in the sudoers file.  Wildcard matching is done via the
  glob(3) and fnmatch(3) functions as specified by IEEE Std 1003.1 (“POSIX.1”).

  *         Matches any set of zero or more characters (including white space).

  ?         Matches any single character (including white space).

  [...]     Matches any character in the specified range.

  [!...]    Matches any character not in the specified range.

  \x        For any character ‘x’, evaluates to ‘x’.  This is used to escape special characters
            such as: ‘*’, ‘?’, ‘[’, and ‘]’.

  NOTE THAT THESE ARE NOT REGULAR EXPRESSIONS.
  Unlike a regular expression there is no way to match one or more characters within a range.

답변2

다른 사람들이 지적했듯이 원하는 것을 지원하지 않으며 sudo범용 와일드카드만 지원합니다.

ers 형식에 와일드카드 문자를 사용하면 몇 가지 심각한 위험이 있습니다 sudo. 예를 들어 허용하면 기본적으로 해당 경로를 사용하는 한 모든 파일에 액세스할 수 있습니다 rm -Rf /some/path/*. 마찬가지로, 상대 경로를 남용할 수 있으며 전달하는 동안에만 다른 경로를 제거할 수 있습니다 .sudo rm -Rf /some/path/blarg /another/not/allowed/pathrmrm -Rf /some/path/../../../../some/path/that/should/be/restricted

입력 유효성 검사를 위해 "프록시" 스크립트를 사용하는 것을 고려할 수 있습니다.

전체 게시물 시리즈를 읽는 것이 좋습니다. 그렇지 않은 경우 최소한 Wildcard의 게시물을 읽어보세요.https://blog.compass-security.com/2012/10/dangerous-sudoers-entries-part-4-wildcards/

관련 정보