Tips for finding Knowledge Articles

  • - Enter just a few key words related to your question or problem
  • - Add Key words to refine your search as necessary
  • - Do not use punctuation
  • - Search is not case sensitive
  • - Avoid non-descriptive filler words like "how", "the", "what", etc.
  • - If you do not find what you are looking for the first time,reduce the number of key words you enter and try searching again.
  • - Minimum supported Internet Explorer version is IE9
Home  >

How to create and test REGEX commands for *NIX privileged commands in Access Manager

11 April,19 at 11:51 AM

Firstly, what is a REGEX command? From Microsoft's documentation, a REGEX command is defined as the following. A regular expression is a pattern that the regular expression engine attempts to match in input text. A pattern consists of one or more character literals, operators, or constructs.


Secondly, what does a REGEX command look like? Here is an example: 





This blog is going to try to take that confusing string of characters and allow you to create your own REGEX commands with a few simple steps and tips. 


Step 1:

Don't get overwhelmed. Just like any other programming code, once you understand the syntax it becomes simpler. Let's take our example from above. What does that command allow the user to do? It's a REGEX command that allows a user to run any command or script in a specific directory. In this case the directory is /home/deploy/Documents/Test


Step 2:

Use sections of previous commands that you know work. 




The above snippet allows for any lowercase letter from a-z along with any uppercase letter from A-Z, any number from 0-9, an underscore, a period and a dash. That pattern covers most of the scripts or commands a user would run. 


The * at the end of the string allows for this pattern to be repeated with the same parameters as many times as needed. 




The $ is the end of the string. 




Now you just have to specify your path, if you require one. The syntax for any path starts with \/ and ends with that same pattern. 


So using that pattern and attaching the above regex, you get our complete command. 




Step 3:

Use this is a tool that will save you so much time. Instead of creating your regex command and creating the command in Access Manager, assigning that to a role definition and then creating a role assignment. Refreshing the cache on your machine and testing the command to only see it fail. 


Regex101 allows you to play with the syntax and get instant match results. 



You insert your command in the 'Regular Expression' box at the top. You can test a sample input that a user would try, in the image above I'm testing a user who wants to run our script in that specific directory. You can see the results are a full match. So my command should work when I import it into Access Manager. 




Here are two more sample commands you can use for free ;)


The first command allows a user to use the chmod command in the specific directory /test/scripts

     a) (chmod) ([0-7]{3,4}) (\/test\/scripts\/[A-Za-z0-9\=_\/\-]+)


The second command allows a user to use the chown command in the same directory /test/scripts

     b) (chown) ([A-Za-z0-9\=_\/\:\-]+) (\/test\/scripts\/[A-Za-z0-9\=_\/\-]+)




When copy and pasting commands you write from regex101 to Access Manager, sometimes special characters won't be copied over correctly. For example, the dash '-' can seem shorter in Access Manager after it's been copied. If the command fails on your UNIX machine but it matches in Regex101 the first thing to rule out is a copy/paste issue. Please type out the full command in Access Manager to avoid this issue. 


For additional regex syntax please reference this MS online document.