> Can we use uid/gid to set permissions instead of username and groupname?

Yes, you sure can.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  bundle agent main
  {
    files:
      
       # Here we use username and groupname
        "/tmp/example"
          create => "true",
          perms => mog( "600", "root", "root" );

       # Here we use uid and gid
        "/tmp/example"
          perms => mog( "600", 1000, 136 );
  }
  body perms mog(mode,user,group)
  # @brief Set the file's mode, owner and group
  # @param mode The new mode
  # @param user The username of the new owner
  # @param group The group name
  {
        owners => { "$(user)" };
        groups => { "$(group)" };
        mode   => "$(mode)";
  }
Example (/tmp/perms-example.cf)

Run the above example:

1
2
  chmod 600 /tmp/perms-example.cf
  sudo cf-agent -KIf /tmp/perms-example.cf
Example execution

Check the results:

    info: Created file '/tmp/example', mode 0600
    info: Owner of '/tmp/example' was 0, setting to 1000
    info: Group of '/tmp/example' was 0, setting to 136
Execution output