@@ -616,6 +616,120 @@ func (c *Conf) CopyKeys(keys []*agent.Key) {
616
616
}
617
617
}
618
618
619
+ // HACK: Adds list of groups to core user
620
+ func (c * Conf ) AddGroups (groups []string ) {
621
+ if c .ignitionV1 != nil {
622
+ c .addGroupsIgnitionV1 (groups )
623
+ } else if c .ignitionV2 != nil {
624
+ c .addGroupsIgnitionV2 (groups )
625
+ } else if c .ignitionV21 != nil {
626
+ c .addGroupsIgnitionV21 (groups )
627
+ } else if c .ignitionV22 != nil {
628
+ c .addGroupsIgnitionV22 (groups )
629
+ } else if c .ignitionV23 != nil {
630
+ c .addGroupsIgnitionV23 (groups )
631
+ }
632
+ }
633
+
634
+ func (c * Conf ) addGroupsIgnitionV1 (groups []string ) {
635
+ for i := range c .ignitionV1 .Passwd .Users {
636
+ user := & c .ignitionV1 .Passwd .Users [i ]
637
+ if user .Name == "core" {
638
+ if user .Create != nil {
639
+ user .Create .Groups = append (user .Create .Groups , groups ... )
640
+ return
641
+ } else {
642
+ user .Create = & v1types.UserCreate {
643
+ Groups : groups ,
644
+ }
645
+ }
646
+ }
647
+ }
648
+ c .ignitionV1 .Passwd .Users = append (c .ignitionV1 .Passwd .Users , v1types.User {
649
+ Name : "core" ,
650
+ Create : & v1types.UserCreate {
651
+ Groups : groups ,
652
+ },
653
+ })
654
+ }
655
+
656
+ func (c * Conf ) addGroupsIgnitionV2 (groups []string ) {
657
+ for i := range c .ignitionV2 .Passwd .Users {
658
+ user := & c .ignitionV2 .Passwd .Users [i ]
659
+ if user .Name == "core" {
660
+ if user .Create != nil {
661
+ user .Create .Groups = append (user .Create .Groups , groups ... )
662
+ return
663
+ } else {
664
+ user .Create = & v2types.UserCreate {
665
+ Groups : groups ,
666
+ }
667
+ return
668
+ }
669
+ }
670
+ }
671
+ c .ignitionV2 .Passwd .Users = append (c .ignitionV2 .Passwd .Users , v2types.User {
672
+ Name : "core" ,
673
+ Create : & v2types.UserCreate {
674
+ Groups : groups ,
675
+ },
676
+ })
677
+ }
678
+
679
+ func (c * Conf ) addGroupsIgnitionV21 (groups []string ) {
680
+ var groupObjs []v21types.PasswdUserGroup
681
+ for _ , group := range groups {
682
+ groupObjs = append (groupObjs , v21types .PasswdUserGroup (group ))
683
+ }
684
+ for i := range c .ignitionV21 .Passwd .Users {
685
+ user := & c .ignitionV21 .Passwd .Users [i ]
686
+ if user .Name == "core" {
687
+ user .Groups = append (user .Groups , groupObjs ... )
688
+ return
689
+ }
690
+ }
691
+ c .ignitionV21 .Passwd .Users = append (c .ignitionV21 .Passwd .Users , v21types.PasswdUser {
692
+ Name : "core" ,
693
+ Groups : groupObjs ,
694
+ })
695
+ }
696
+
697
+ func (c * Conf ) addGroupsIgnitionV22 (groups []string ) {
698
+ var groupObjs []v22types.Group
699
+ for _ , group := range groups {
700
+ groupObjs = append (groupObjs , v22types .Group (group ))
701
+ }
702
+ for i := range c .ignitionV22 .Passwd .Users {
703
+ user := & c .ignitionV22 .Passwd .Users [i ]
704
+ if user .Name == "core" {
705
+ user .Groups = append (user .Groups , groupObjs ... )
706
+ return
707
+ }
708
+ }
709
+ c .ignitionV22 .Passwd .Users = append (c .ignitionV22 .Passwd .Users , v22types.PasswdUser {
710
+ Name : "core" ,
711
+ Groups : groupObjs ,
712
+ })
713
+ }
714
+
715
+ func (c * Conf ) addGroupsIgnitionV23 (groups []string ) {
716
+ var groupObjs []v23types.Group
717
+ for _ , group := range groups {
718
+ groupObjs = append (groupObjs , v23types .Group (group ))
719
+ }
720
+ for i := range c .ignitionV23 .Passwd .Users {
721
+ user := & c .ignitionV23 .Passwd .Users [i ]
722
+ if user .Name == "core" {
723
+ user .Groups = append (user .Groups , groupObjs ... )
724
+ return
725
+ }
726
+ }
727
+ c .ignitionV23 .Passwd .Users = append (c .ignitionV23 .Passwd .Users , v23types.PasswdUser {
728
+ Name : "core" ,
729
+ Groups : groupObjs ,
730
+ })
731
+ }
732
+
619
733
func keysToStrings (keys []* agent.Key ) (keyStrs []string ) {
620
734
for _ , key := range keys {
621
735
keyStrs = append (keyStrs , key .String ())
0 commit comments