amazon-ssm-agent icon indicating copy to clipboard operation
amazon-ssm-agent copied to clipboard

"panic: runtime error: slice bounds out of range" when registering agent

Open robdew opened this issue 8 years ago • 3 comments

I've gone through several installation attempts (with dpkg -i and dpkg -p in between) and can't seem to resolve the following error when registering the agent:

user@host:~$ rm -r /tmp/ssm && mkdir /tmp/ssm
user@host:~$ sudo curl https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/debian_amd64/amazon-ssm-agent.deb -o /tmp/ssm/amazon-ssm-agent.deb
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 11.5M  100 11.5M    0     0  5920k      0  0:00:01  0:00:01 --:--:-- 5919k
user@host:~$ sudo dpkg -i /tmp/ssm/amazon-ssm-agent.deb
Selecting previously unselected package amazon-ssm-agent.
(Reading database ... 75560 files and directories currently installed.)
Preparing to unpack /tmp/ssm/amazon-ssm-agent.deb ...
Preparing for install
Warning: amazon-ssm-agent.service changed on disk. Run 'systemctl daemon-reload' to reload units.
Unpacking amazon-ssm-agent (2.2.136.0-1) ...
Setting up amazon-ssm-agent (2.2.136.0-1) ...
Starting agent
Created symlink from /etc/systemd/system/network-online.target.wants/amazon-ssm-agent.service to /lib/systemd/system/amazon-ssm-agent.service.
Processing triggers for ureadahead (0.100.0-19) ...
user@host:~$ systemctl daemon-reloa
Unknown operation daemon-reloa.
user@host:~$ systemctl daemon-reload
Failed to execute operation: The name org.freedesktop.PolicyKit1 was not provided by any .service files
user@host:~$ sudo service amazon-ssm-agent stop
user@host:~$ sudo amazon-ssm-agent -register -code "redacted" -id "redacted" -region "us-east-1" 
Error occurred fetching the seelog config file path:  open /etc/amazon/ssm/seelog.xml: no such file or directory
Initializing new seelog logger
New Seelog Logger Creation Complete
2018-01-14 17:19:14 INFO Start File Watcher On: /etc/amazon/ssm/seelog.xml
panic: runtime error: slice bounds out of range

goroutine 1 [running]:
github.com/aws/aws-sdk-go/aws/ec2metadata.(*EC2Metadata).Region(0xc42000e600, 0xc4204d1480, 0x866cd5, 0x0, 0x0)
	/local/p4clients/pkgbuild-hBXYk/workspace/src/Amazon-ssm-agent/vendor/src/github.com/aws/aws-sdk-go/aws/ec2metadata/api.go:122 +0xb7
github.com/aws/amazon-ssm-agent/agent/platform.instanceMetadata.Region(0xc42000e600, 0x0, 0x0, 0x42a5b9, 0xc400000008)
	/local/p4clients/pkgbuild-hBXYk/workspace/src/Amazon-ssm-agent/build/private/src/github.com/aws/amazon-ssm-agent/agent/platform/instance_info_deps.go:60 +0x2b
github.com/aws/amazon-ssm-agent/agent/platform.fetchRegion(0x8, 0xc66fc0, 0x10f8350, 0x1c0)
	/local/p4clients/pkgbuild-hBXYk/workspace/src/Amazon-ssm-agent/build/private/src/github.com/aws/amazon-ssm-agent/agent/platform/instance_info.go:189 +0x64
github.com/aws/amazon-ssm-agent/agent/platform.Region(0x0, 0x0, 0x0, 0x0)
	/local/p4clients/pkgbuild-hBXYk/workspace/src/Amazon-ssm-agent/build/private/src/github.com/aws/amazon-ssm-agent/agent/platform/instance_info.go:85 +0x9d
github.com/aws/amazon-ssm-agent/agent/ssm/util.AwsConfig(0xada180)
	/local/p4clients/pkgbuild-hBXYk/workspace/src/Amazon-ssm-agent/build/private/src/github.com/aws/amazon-ssm-agent/agent/ssm/util/util.go:43 +0x366
github.com/aws/aws-sdk-go/aws.(*Config).WithLogLevel(...)
	/local/p4clients/pkgbuild-hBXYk/workspace/src/Amazon-ssm-agent/build/private/src/github.com/aws/amazon-ssm-agent/agent/ssm/anonauth/anon_service.go:42
github.com/aws/amazon-ssm-agent/agent/ssm/anonauth.NewAnonymousService(0x7ffd29ab98d8, 0x9, 0x0, 0x0)
	/local/p4clients/pkgbuild-hBXYk/workspace/src/Amazon-ssm-agent/build/private/src/github.com/aws/amazon-ssm-agent/agent/ssm/anonauth/anon_service.go:42 +0xa3
main.registerManagedInstance(0x0, 0x0, 0x0, 0xc4201adea8)
	/local/p4clients/pkgbuild-hBXYk/workspace/src/Amazon-ssm-agent/agent/agent_parser.go:152 +0x328
main.processRegistration(0x10a16a0, 0xc4201b43a0, 0x1)
	/local/p4clients/pkgbuild-hBXYk/workspace/src/Amazon-ssm-agent/agent/agent_parser.go:111 +0xce
main.parseFlags(0x10a16a0, 0xc4201b43a0)
	/local/p4clients/pkgbuild-hBXYk/workspace/src/Amazon-ssm-agent/agent/agent_parser.go:63 +0x3fa
main.main()
	/local/p4clients/pkgbuild-hBXYk/workspace/src/Amazon-ssm-agent/agent/agent_unix.go:14 +0x99

The error.log just shows repeats of this:

error log
2018-01-14 17:20:46 ERROR [func1 @ agent.go.56] Agent crashed with message runtime error: slice bounds out of range!

agent log errors after attempting to register:

2018-01-14 17:18:33 INFO Start File Watcher On: /etc/amazon/ssm/seelog.xml
2018-01-14 17:18:33 INFO Starting Agent: amazon-ssm-agent - v2.2.136.0
2018-01-14 17:18:33 INFO OS: linux, Arch: amd64
2018-01-14 17:18:33 ERROR Agent crashed with message runtime error: slice bounds out of range!
2018-01-14 17:19:04 INFO Got signal:terminated value:0xa53f60
2018-01-14 17:19:04 INFO Stopping agent

this is my own linux server not an ec2 instance:

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.3 LTS"
VERSION="16.04.3 LTS (Xenial Xerus)"
...
Linux  4.4.0-109-generic #132-Ubuntu SMP Tue Jan 9 19:52:39 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

robdew avatar Jan 14 '18 17:01 robdew

@robdew Did you solve this problem? I also encountered the same problem, but in my environment it was due to IP (169.254.169.254) returning EC2 metadata, another API was provided. It is probably the same cause if you can execute the following and get the result without causing an error.

curl http://169.254.169.254/meta-data/

I succeeded in installing ssm-agent by prohibiting access to 169.254.169.254 with iptables.

kan avatar Oct 25 '18 06:10 kan

I did not solve the problem I gave up.

robdew avatar Oct 28 '18 16:10 robdew

Issue was fixed as part of this pull-request in aws-sdk-go: https://github.com/aws/aws-sdk-go/pull/2380

ferkhat-aws avatar Feb 18 '21 16:02 ferkhat-aws