我正在尝试创建如下所示的打包程序版本,但权限被拒绝。由于我在尝试执行 shell 脚本时也遇到了同样的问题,因此我认为根本原因可能是操作系统层配置错误(见下文)。这里的问题是,使用 shell 脚本时,我有一个运行“bash scriptname.sh”的变通方法,而使用打包程序时我没有这个选项。
PACKER_LOG=1 packer init .
+ PACKER_LOG=1
+ packer init .
2024/05/06 11:35:03 [INFO] Packer version: 1.10.3 [go1.20.12 linux amd64]
2024/05/06 11:35:03 [TRACE] discovering plugins in /usr/bin
2024/05/06 11:35:03 [TRACE] discovering plugins in .
2024/05/06 11:35:03 [TRACE] discovering plugins in /home/userid/.config/packer/plugins
2024/05/06 11:35:03 [INFO] PACKER_CONFIG env var not set; checking the default config file path
2024/05/06 11:35:03 [INFO] PACKER_CONFIG env var set; attempting to open config file: /home/userid/.packerconfig
2024/05/06 11:35:03 [WARN] Config file doesn't exist: /home/userid/.packerconfig
2024/05/06 11:35:03 [INFO] Setting cache directory: /home/userid/.cache/packer
2024/05/06 11:35:03 [TRACE] init: plugingetter.ListInstallationsOptions{FromFolders:[]string{"/usr/bin", ".", "/home/userid/.config/packer/plugins"}, BinaryInstallationOptions:plugingetter.BinaryInstallationOptions{APIVersionMajor:"5", APIVersionMinor:"0", OS:"linux", ARCH:"amd64", Ext:"", Checksummers:[]plugingetter.Checksummer{plugingetter.Checksummer{Type:"sha256", Hash:(*sha256.digest)(0xc00035d400)}}}}
2024/05/06 11:35:03 [TRACE] listing potential installations for "github.com/hashicorp/vsphere" that match "~> 1". plugingetter.ListInstallationsOptions{FromFolders:[]string{"/usr/bin", ".", "/home/userid/.config/packer/plugins"}, BinaryInstallationOptions:plugingetter.BinaryInstallationOptions{APIVersionMajor:"5", APIVersionMinor:"0", OS:"linux", ARCH:"amd64", Ext:"", Checksummers:[]plugingetter.Checksummer{plugingetter.Checksummer{Type:"sha256", Hash:(*sha256.digest)(0xc00035d400)}}}}
2024/05/06 11:35:03 [TRACE] getting available versions for the github.com/hashicorp/vsphere plugin
2024/05/06 11:35:03 [WARNING] github-getter: no GitHub token set, if you intend to install plugins often, please set the PACKER_GITHUB_API_TOKEN env var
2024/05/06 11:35:03 [DEBUG] github-getter: getting "https://api.github.com/repos/hashicorp/packer-plugin-vsphere/git/matching-refs/tags"
2024/05/06 11:35:04 [DEBUG] will try to install: [1.2.7 1.2.6 1.2.5 1.2.4 1.2.3 1.2.2 1.2.1 1.2.0 1.1.2 1.1.1 1.1.0 1.0.8 1.0.7 1.0.6 1.0.5 1.0.4 1.0.3 1.0.2 1.0.1 1.0.0]
2024/05/06 11:35:04 [TRACE] fetching checksums file for the "1.2.7" version of the github.com/hashicorp/vsphere plugin in "/home/userid/.config/packer/plugins/github.com/hashicorp/vsphere"...
2024/05/06 11:35:04 [DEBUG] github-getter: getting "https://github.com/hashicorp/packer-plugin-vsphere/releases/download/v1.2.7/packer-plugin-vsphere_v1.2.7_SHA256SUMS"
2024/05/06 11:35:04 [TRACE] ignoring invalid remote binary packer-plugin-vsphere_v1.2.7_x5.0_darwin_amd64.zip: wrong system, expected linux_amd64
2024/05/06 11:35:04 [TRACE] ignoring invalid remote binary packer-plugin-vsphere_v1.2.7_x5.0_darwin_arm64.zip: wrong system, expected linux_amd64
2024/05/06 11:35:04 [TRACE] ignoring invalid remote binary packer-plugin-vsphere_v1.2.7_x5.0_freebsd_386.zip: wrong system, expected linux_amd64
2024/05/06 11:35:04 [TRACE] ignoring invalid remote binary packer-plugin-vsphere_v1.2.7_x5.0_freebsd_amd64.zip: wrong system, expected linux_amd64
2024/05/06 11:35:04 [TRACE] ignoring invalid remote binary packer-plugin-vsphere_v1.2.7_x5.0_freebsd_arm.zip: wrong system, expected linux_amd64
2024/05/06 11:35:04 [TRACE] ignoring invalid remote binary packer-plugin-vsphere_v1.2.7_x5.0_linux_386.zip: wrong system, expected linux_amd64
2024/05/06 11:35:04 [TRACE] About to get: packer-plugin-vsphere_v1.2.7_x5.0_linux_amd64.zip
2024/05/06 11:35:04 [DEBUG] github-getter: getting "https://github.com/hashicorp/packer-plugin-vsphere/releases/download/v1.2.7/packer-plugin-vsphere_v1.2.7_x5.0_linux_amd64.zip"
Installed plugin github.com/hashicorp/vsphere v1.2.7 in "/home/userid/.config/packer/plugins/github.com/hashicorp/vsphere/packer-plugin-vsphere_v1.2.7_x5.0_linux_amd64"
2024/05/06 11:35:05 [INFO] (telemetry) Finalizing.
2024/05/06 11:35:06 waiting for all plugin processes to complete...
++ date +%Y%m%dt%H%M%S
+ packer build -var vm_name=name-here -var-file=pkrvars/pkrvars.hcl .
Error loading configuration:
fork/exec /home/userid/.config/packer/plugins/github.com/hashicorp/vsphere/packer-plugin-vsphere_v1.2.7_x5.0_linux_amd64: permission denied
然而,目录权限对我来说看起来很好:
[userid@host vsphere]$ ls -la /home/userid/.config/packer/plugins
total 0
drwxr-xr-x. 3 userid userid 24 May 6 11:35 .
drwxr-xr-x. 3 userid userid 73 May 6 11:35 ..
drwxr-xr-x. 3 userid userid 23 May 6 11:35 github.com
[userid@host vsphere]$ ls -la /home/userid/.config/packer/plugins/github.com/hashicorp/vsphere/
total 61096
drwxr-xr-x. 2 userid userid 122 May 6 11:35 .
drwxr-xr-x. 3 userid userid 21 May 6 11:35 ..
-rwxr-xr-x. 1 userid userid 62558208 May 6 11:35 packer-plugin-vsphere_v1.2.7_x5.0_linux_amd64
-rw-r--r--. 1 userid userid 64 May 6 11:35 packer-plugin-vsphere_v1.2.7_x5.0_linux_amd64_SHA256SUM
[userid@host vsphere]$ file packer-plugin-vsphere_v1.2.7_x5.0_linux_amd64
packer-plugin-vsphere_v1.2.7_x5.0_linux_amd64: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped
如果我将构建语句替换为以下内容,我会得到同样的错误:
PACKER_LOG=1 packer plugins install github.com/hashicorp/vsphere
话虽如此,我感觉它与以下内容有关,即我无法运行./executable。
[userid@host vsphere]$ vi test.sh
[userid@host vsphere]$ chmod 0755 test.sh
[userid@host vsphere]$ ./test.sh
-bash: ./test.sh: Permission denied
[userid@host vsphere]$ bash test.sh
This is a test
[userid@host vsphere]$ cat test.sh
#!/bin/bash
echo "This is a test"
同样,执行插件可执行文件也不起作用:
[userid@host vsphere]$ . ./packer-plugin-vsphere_v1.2.7_x5.0_linux_amd64
-bash: .: ./packer-plugin-vsphere_v1.2.7_x5.0_linux_amd64: cannot execute binary file
[user@host vsphere]$ ./packer-plugin-vsphere_v1.2.7_x5.0_linux_amd64
-bash: ./packer-plugin-vsphere_v1.2.7_x5.0_linux_amd64: Permission denied
[user@host vsphere]$ export PATH=${PATH}:.
[user@host vsphere]$ packer-plugin-vsphere_v1.2.7_x5.0_linux_amd64
-bash: ./packer-plugin-vsphere_v1.2.7_x5.0_linux_amd64: Permission denied
我不认为这与 SELinux 相关,因为下面的输出对我来说看起来不错。
[user@host vsphere]$ ls -latZ .
total 61104
drwxr-xr-x. 2 userid userid unconfined_u:object_r:config_home_t:s0 4096 May 6 15:17 .
-rwxr-xr-x. 1 userid userid unconfined_u:object_r:config_home_t:s0 35 May 6 15:17 test.sh
-rw-r--r--. 1 userid userid unconfined_u:object_r:config_home_t:s0 0 May 6 14:56 plugins.hwm
-rw-r--r--. 1 userid userid unconfined_u:object_r:config_home_t:s0 0 May 6 14:56 plugins.pwd
-rw-r--r--. 1 userid userid unconfined_u:object_r:config_home_t:s0 0 May 6 14:56 plugins.pwi
-rw-r--r--. 1 userid userid unconfined_u:object_r:config_home_t:s0 64 May 6 11:35 packer-plugin-vsphere_v1.2.7_x5.0_linux_amd64_SHA256SUM
-rwxr-xr-x. 1 userid userid unconfined_u:object_r:config_home_t:s0 62558208 May 6 11:35 packer-plugin-vsphere_v1.2.7_x5.0_linux_amd64
drwxr-xr-x. 3 userid userid unconfined_u:object_r:config_home_t:s0 21 May 6 11:35 ..
通过运行 setenforce=0 并重新运行上述操作,我进一步确认这与 SELinux 无关。
关于如何让打包插件正常工作,您有什么想法吗?