Repository: osbuild/osbuild-composer
Pull request #2240 (2022-01-30 21:32:44)

Mock OpenID: add token type, expires in and scope fields
According to (rfc6749)[https://datatracker.ietf.org/doc/html/rfc6749#section-3.3] the `token_type` is required. Additionally, allow setting `expires_in` and `scope`.


Patch:
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 810c6d525..12cc8898d 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -469,6 +469,7 @@ SCHEDULED_CLOUD_CLEANER:
     - terraform
   variables:
     RUNNER: aws/centos-stream-8-x86_64
+    INTERNAL_NETWORK: "true"
   rules:
     - if: '$CI_PIPELINE_SOURCE == "schedule" && $CLEANUP == "true"'
   script:
diff --git a/cmd/osbuild-mock-openid-provider/main.go b/cmd/osbuild-mock-openid-provider/main.go
index 941b4a5bb..2be1d7b23 100644
--- a/cmd/osbuild-mock-openid-provider/main.go
+++ b/cmd/osbuild-mock-openid-provider/main.go
@@ -21,11 +21,15 @@ func main() {
 	var rsaPem string
 	var tlsCert string
 	var tlsKey string
+	var tokenExpires int
+	var tokenScope string
 	flag.StringVar(&addr, "a", "localhost:8080", "Address to serve on")
 	flag.StringVar(&rsaPubPem, "rsaPubPem", "", "rsa pubkey in pem format (path)")
 	flag.StringVar(&rsaPem, "rsaPem", "", "rsa privkey in pem format (path)")
 	flag.StringVar(&tlsCert, "cert", "", "tls cert")
 	flag.StringVar(&tlsKey, "key", "", "tls key")
+	flag.IntVar(&tokenExpires, "expires", 60, "Expiration of the token in seconds (default: 360))")
+	flag.StringVar(&tokenScope, "scope", "", "The scope of the token (default: not set)")
 	flag.Parse()
 
 	if rsaPubPem == "" || rsaPem == "" {
@@ -102,12 +106,19 @@ func main() {
 			panic(err)
 		}
 
+		// See https://datatracker.ietf.org/doc/html/rfc6749
 		type response struct {
 			AccessToken string `json:"access_token"`
+			TokenType   string `json:"token_type"`           // required
+			ExpiresIn   int    `json:"expires_in,omitempty"` // lifetime in seconds
+			Scope       string `json:"scope,omitempty"`
 		}
 
 		err = json.NewEncoder(w).Encode(response{
 			AccessToken: tokenStr,
+			TokenType:   "Bearer",
+			ExpiresIn:   tokenExpires,
+			Scope:       tokenScope,
 		})
 		if err != nil {
 			panic(err)
diff --git a/internal/distro/rhel86/partition_tables.go b/internal/distro/rhel86/partition_tables.go
index aa088d0f2..ed465a590 100644
--- a/internal/distro/rhel86/partition_tables.go
+++ b/internal/distro/rhel86/partition_tables.go
@@ -155,7 +155,7 @@ var ec2BasePartitionTables = distro.BasePartitionTableMap{
 				},
 			},
 			{
-				Size: 1048676,
+				Size: 1048576,
 				Type: disk.FilesystemDataGUID,
 				UUID: disk.FilesystemDataUUID,
 				Filesystem: &disk.Filesystem{
diff --git a/schutzbot/scheduled_cloud_cleaner.sh b/schutzbot/scheduled_cloud_cleaner.sh
index 2cf440def..c1963e50e 100755
--- a/schutzbot/scheduled_cloud_cleaner.sh
+++ b/schutzbot/scheduled_cloud_cleaner.sh
@@ -276,3 +276,38 @@ for image in $IMAGES; do
                 echo "deleted image: ${NAME}"        
 	fi
 done
+
+
+#---------------------------------------------------------------
+#                       vmware cleanup
+#---------------------------------------------------------------
+
+greenprint "starting vmware cleanup"
+
+GOVC_CMD=/tmp/govc
+
+# We need govc to talk to vSphere
+if ! hash govc; then
+    greenprint "Installing govc"
+    pushd /tmp || exit
+        curl -Ls --retry 5 --output govc.gz \
+            https://github.com/vmware/govmomi/releases/download/v0.24.0/govc_linux_amd64.gz
+        gunzip -f govc.gz
+        chmod +x /tmp/govc
+        $GOVC_CMD version
+    popd || exit
+fi
+
+GOVC_AUTH="${GOVMOMI_USERNAME}:${GOVMOMI_PASSWORD}@${GOVMOMI_URL}"
+
+TAGGED=$($GOVC_CMD tags.attached.ls -u "${GOVC_AUTH}" -k "gitlab-ci-test" | xargs -r ${GOVC_CMD} ls -u "${GOVC_AUTH}" -k -L)
+
+for vm in $TAGGED; do
+	# Could use JSON output, but it takes much longer, as it includes more properties
+	CREATION_TIME=$($GOVC_CMD vm.info -u "${GOVC_AUTH}" -k "${vm}" | awk '$1 ~ /^ *Boot/ { print $3 " " $4 $5 }')
+	
+	if [[ $(date -d "${CREATION_TIME}" +%s) -lt ${DELETE_TIME} ]]; then
+                $GOVC_CMD vm.destroy -u "${GOVC_AUTH}" -k "${vm}"
+                echo "destroyed vm: ${vm}"
+	fi
+done


Test patch:
diff --git a/test/cases/vmware.sh b/test/cases/vmware.sh
index f1e921085..ac60b418a 100755
--- a/test/cases/vmware.sh
+++ b/test/cases/vmware.sh
@@ -196,6 +196,12 @@ $GOVC_CMD vm.create -u "${GOVMOMI_USERNAME}":"${GOVMOMI_PASSWORD}"@"${GOVMOMI_UR
     --disk.controller=ide \
     "${IMAGE_KEY}"
 
+# tagging vm as testing object
+$GOVC_CMD tags.attach -u "${GOVMOMI_USERNAME}":"${GOVMOMI_PASSWORD}"@"${GOVMOMI_URL}" \
+    -k=true \
+    -c "osbuild-composer testing" gitlab-ci-test \
+    "/${GOVMOMI_DATACENTER}/vm/${GOVMOMI_FOLDER}/${IMAGE_KEY}"
+
 greenprint "Getting IP of created VM"
 VM_IP=$($GOVC_CMD vm.ip -u "${GOVMOMI_USERNAME}":"${GOVMOMI_PASSWORD}"@"${GOVMOMI_URL}" -k=true "${IMAGE_KEY}")
 
diff --git a/test/data/manifests/centos_8-aarch64-ami-boot.json b/test/data/manifests/centos_8-aarch64-ami-boot.json
index 0b269616a..acf5f4e70 100644
--- a/test/data/manifests/centos_8-aarch64-ami-boot.json
+++ b/test/data/manifests/centos_8-aarch64-ami-boot.json
@@ -1101,14 +1101,14 @@
                   "uuid": "68B2905B-DF3E-4FB3-80FA-49D1E773AA33"
                 },
                 {
-                  "size": 1048676,
+                  "size": 1048576,
                   "start": 411648,
                   "type": "0FC63DAF-8483-4772-8E79-3D69D8477DE4",
                   "uuid": "CB07C243-BC44-4717-853E-28852021225B"
                 },
                 {
-                  "size": 19511096,
-                  "start": 1460324,
+                  "size": 19511196,
+                  "start": 1460224,
                   "type": "0FC63DAF-8483-4772-8E79-3D69D8477DE4",
                   "uuid": "6264D520-3FB9-423F-8AB8-7A0A8E3D3562"
                 }
@@ -1150,7 +1150,7 @@
                 "options": {
                   "filename": "image.raw",
                   "start": 411648,
-                  "size": 1048676
+                  "size": 1048576
                 }
               }
             }
@@ -1166,8 +1166,8 @@
                 "type": "org.osbuild.loopback",
                 "options": {
                   "filename": "image.raw",
-                  "start": 1460324,
-                  "size": 19511096
+                  "start": 1460224,
+                  "size": 19511196
                 }
               }
             }
@@ -1197,7 +1197,7 @@
                 "options": {
                   "filename": "image.raw",
                   "start": 411648,
-                  "size": 1048676
+                  "size": 1048576
                 }
               },
               "efi": {
@@ -1212,8 +1212,8 @@
                 "type": "org.osbuild.loopback",
                 "options": {
                   "filename": "image.raw",
-                  "start": 1460324,
-                  "size": 19511096
+                  "start": 1460224,
+                  "size": 19511196
                 }
               }
             },
diff --git a/test/data/manifests/rhel_86-aarch64-ami-boot.json b/test/data/manifests/rhel_86-aarch64-ami-boot.json
index 37f811681..4b0090907 100644
--- a/test/data/manifests/rhel_86-aarch64-ami-boot.json
+++ b/test/data/manifests/rhel_86-aarch64-ami-boot.json
@@ -1128,14 +1128,14 @@
                   "uuid": "68B2905B-DF3E-4FB3-80FA-49D1E773AA33"
                 },
                 {
-                  "size": 1048676,
+                  "size": 1048576,
                   "start": 411648,
                   "type": "0FC63DAF-8483-4772-8E79-3D69D8477DE4",
                   "uuid": "CB07C243-BC44-4717-853E-28852021225B"
                 },
                 {
-                  "size": 19511096,
-                  "start": 1460324,
+                  "size": 19511196,
+                  "start": 1460224,
                   "type": "0FC63DAF-8483-4772-8E79-3D69D8477DE4",
                   "uuid": "6264D520-3FB9-423F-8AB8-7A0A8E3D3562"
                 }
@@ -1177,7 +1177,7 @@
                 "options": {
                   "filename": "image.raw",
                   "start": 411648,
-                  "size": 1048676
+                  "size": 1048576
                 }
               }
             }
@@ -1193,8 +1193,8 @@
                 "type": "org.osbuild.loopback",
                 "options": {
                   "filename": "image.raw",
-                  "start": 1460324,
-                  "size": 19511096
+                  "start": 1460224,
+                  "size": 19511196
                 }
               }
             }
@@ -1224,7 +1224,7 @@
                 "options": {
                   "filename": "image.raw",
                   "start": 411648,
-                  "size": 1048676
+                  "size": 1048576
                 }
               },
               "efi": {
@@ -1239,8 +1239,8 @@
                 "type": "org.osbuild.loopback",
                 "options": {
                   "filename": "image.raw",
-                  "start": 1460324,
-                  "size": 19511096
+                  "start": 1460224,
+                  "size": 19511196
                 }
               }
             },
diff --git a/test/data/manifests/rhel_86-aarch64-ec2-boot.json b/test/data/manifests/rhel_86-aarch64-ec2-boot.json
index 71bd2af49..a0904bc31 100644
--- a/test/data/manifests/rhel_86-aarch64-ec2-boot.json
+++ b/test/data/manifests/rhel_86-aarch64-ec2-boot.json
@@ -1142,14 +1142,14 @@
                   "uuid": "68B2905B-DF3E-4FB3-80FA-49D1E773AA33"
                 },
                 {
-                  "size": 1048676,
+                  "size": 1048576,
                   "start": 411648,
                   "type": "0FC63DAF-8483-4772-8E79-3D69D8477DE4",
                   "uuid": "CB07C243-BC44-4717-853E-28852021225B"
                 },
                 {
-                  "size": 19511096,
-                  "start": 1460324,
+                  "size": 19511196,
+                  "start": 1460224,
                   "type": "0FC63DAF-8483-4772-8E79-3D69D8477DE4",
                   "uuid": "6264D520-3FB9-423F-8AB8-7A0A8E3D3562"
                 }
@@ -1191,7 +1191,7 @@
                 "options": {
                   "filename": "image.raw",
                   "start": 411648,
-                  "size": 1048676
+                  "size": 1048576
                 }
               }
             }
@@ -1207,8 +1207,8 @@
                 "type": "org.osbuild.loopback",
                 "options": {
                   "filename": "image.raw",
-                  "start": 1460324,
-                  "size": 19511096
+                  "start": 1460224,
+                  "size": 19511196
                 }
               }
             }
@@ -1238,7 +1238,7 @@
                 "options": {
                   "filename": "image.raw",
                   "start": 411648,
-                  "size": 1048676
+                  "size": 1048576
                 }
               },
               "efi": {
@@ -1253,8 +1253,8 @@
                 "type": "org.osbuild.loopback",
                 "options": {
                   "filename": "image.raw",
-                  "start": 1460324,
-                  "size": 19511096
+                  "start": 1460224,
+                  "size": 19511196
                 }
               }
             },