@@ -23,7 +23,7 @@ import (
2323 "github.com/ibm-messaging/mq-container/internal/command"
2424)
2525
26- const groupName string = "suplgroup "
26+ const groupName string = "supplgrp "
2727
2828func verifyCurrentUser () error {
2929 log .Debug ("Verifying current user information" )
@@ -36,9 +36,9 @@ func verifyCurrentUser() error {
3636 // Not supported yet
3737 return fmt .Errorf ("Container is running as mqm user which is not supported. Please run this container as root" )
3838 } else if curUser .Username == "root" {
39- // We're running as root so need to check for suplimentary groups.
40- // We can't use the golang User.GroupIDs as it doesn't seem to detect container supplimentary groups..
41- groups , err := getCurrentGroups ()
39+ // We're running as root so need to check for supplementary groups.
40+ // We can't use the golang User.GroupIDs as it doesn't seem to detect container supplementary groups..
41+ groups , err := getCurrentUserGroups ()
4242 for _ , e := range groups {
4343 _ , _ , testGroup := command .Run ("getent" , "group" , e )
4444 if testGroup != nil {
@@ -64,9 +64,9 @@ func verifyCurrentUser() error {
6464}
6565
6666func logUser () {
67- u , err := user .Current ()
68- if err == nil {
69- g , err := getCurrentGroups ()
67+ u , usererr := user .Current ()
68+ if usererr == nil {
69+ g , err := getCurrentUserGroups ()
7070 if err != nil && len (g ) == 0 {
7171 log .Printf ("Running as user ID %v (%v) with primary group %v" , u .Uid , u .Name , u .Gid )
7272 } else {
@@ -77,12 +77,30 @@ func logUser() {
7777 g = append (g [:i ], g [i + 1 :]... )
7878 }
7979 }
80- log .Printf ("Running as user ID %v (%v) with primary group %v, and supplemental groups %v" , u .Uid , u .Name , u .Gid , strings .Join (g , "," ))
80+ log .Printf ("Running as user ID %v (%v) with primary group %v, and supplementary groups %v" , u .Uid , u .Name , u .Gid , strings .Join (g , "," ))
81+ }
82+ }
83+
84+ if usererr == nil && u .Username != "mqm" {
85+ mqm , err := user .Lookup ("mqm" )
86+ // Need to print out mqm user details as well.
87+ g , err := getUserGroups (mqm )
88+ if err != nil && len (g ) == 0 {
89+ log .Printf ("MQM user ID %v (%v) has primary group %v" , mqm .Uid , "mqm" , mqm .Gid )
90+ } else {
91+ // Look for the primary group in the list of group IDs
92+ for i , v := range g {
93+ if v == mqm .Gid {
94+ // Remove the element from the slice
95+ g = append (g [:i ], g [i + 1 :]... )
96+ }
97+ }
98+ log .Printf ("MQM user ID %v (%v) has primary group %v, and supplementary groups %v" , mqm .Uid , "mqm" , mqm .Gid , strings .Join (g , "," ))
8199 }
82100 }
83101}
84102
85- func getCurrentGroups () ([]string , error ) {
103+ func getCurrentUserGroups () ([]string , error ) {
86104 var nilArray []string
87105 out , _ , err := command .Run ("id" , "--groups" )
88106 if err != nil {
@@ -99,3 +117,21 @@ func getCurrentGroups() ([]string, error) {
99117 groups := strings .Split (out , " " )
100118 return groups , nil
101119}
120+
121+ func getUserGroups (usr * user.User ) ([]string , error ) {
122+ var nilArray []string
123+ out , _ , err := command .Run ("id" , "--groups" , usr .Uid )
124+ if err != nil {
125+ log .Debugf ("Unable to get user %s groups" , usr .Uid )
126+ return nilArray , err
127+ }
128+
129+ out = strings .TrimSpace (out )
130+ if out == "" {
131+ // we don't have any groups?
132+ return nilArray , fmt .Errorf ("Unable to determine groups for user %s" , usr .Uid )
133+ }
134+
135+ groups := strings .Split (out , " " )
136+ return groups , nil
137+ }
0 commit comments