{"id":21134117,"url":"https://github.com/horgix/cfn-init-symlink-bugreport","last_synced_at":"2025-03-14T12:41:30.400Z","repository":{"id":95050860,"uuid":"77049659","full_name":"Horgix/cfn-init-symlink-bugreport","owner":"Horgix","description":":bug: Explanations and minimal example to reproduce a bug on CloudFormation, affecting the way cfn-init handles symlinks to be created","archived":false,"fork":false,"pushed_at":"2017-04-09T17:14:47.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-05T17:46:06.850Z","etag":null,"topics":["aws","bugreport","cfn","cloudformation","symlink"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Horgix.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-12-21T12:28:37.000Z","updated_at":"2017-03-03T15:43:37.000Z","dependencies_parsed_at":"2023-06-11T22:47:47.418Z","dependency_job_id":null,"html_url":"https://github.com/Horgix/cfn-init-symlink-bugreport","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Horgix%2Fcfn-init-symlink-bugreport","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Horgix%2Fcfn-init-symlink-bugreport/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Horgix%2Fcfn-init-symlink-bugreport/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Horgix%2Fcfn-init-symlink-bugreport/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Horgix","download_url":"https://codeload.github.com/Horgix/cfn-init-symlink-bugreport/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243581060,"owners_count":20314162,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","bugreport","cfn","cloudformation","symlink"],"created_at":"2024-11-20T06:23:34.023Z","updated_at":"2025-03-14T12:41:30.382Z","avatar_url":"https://github.com/Horgix.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"This repository contains a minimum example for what looks like a bug on\ncfn-init.\n\n# The problem itself\n\n## Context\n\nSimply using `cfn-init` to create a symlink described in the `Metadata`\nproperty given to an `AWS::EC2::Instance` object.\n\nRelevant parts of the documentation, taken from\n\u003chttp://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-init.html\u003e :\n\n\u003e content: [...] When you create a symlink, specify the symlink target as the content.\n\n\u003e mode: [...] Use the first three digits for symlinks and the last three digits\n\u003e for setting permissions. To create a symlink, specify 120000. To specify\n\u003e permissions for a file, use the last three digits, such as 000644.\n\n\u003e The following example snippet creates a symlink /tmp/myfile2.txt that points\n\u003e at an existing file /tmp/myfile1.txt.\n\n```\nfiles: \n  /tmp/myfile2.txt: \n    content: \"/tmp/myfile1.txt\"\n    mode: \"120000\"\n```\n\nFrom my understanding, creating a symlink to a file should not modify the\nlinked file.\n\n## Stack \"without mode\"\n\nTake the stack described in the `no-mode` tag of this repository, with the\nfollowing Metadata:\n\n```\nMetadata:\n  AWS::CloudFormation::Init:\n    config:\n      files:\n        \"/home/ubuntu/demo_link\":\n          content: \"/etc/issue\"\n          owner:  \"ubuntu\"\n          group:  \"ubuntu\"\n```\n\nWhat is **expected** is a simple file `/home/ubuntu/deno_link` with\n`/etc/issue` as **content** (not a symlink in any way). Let's see how it goes.\n\n```\n$ ls -la /home/ubuntu/demo_link \n-rw-r--r-- 1 ubuntu ubuntu 10 Dec 21 10:45 /home/ubuntu/demo_link\n```\n\nThis is fine. Plain file with `0644` default mode, as expected.\n\n```\n$ cat /home/ubuntu/demo_link \n/etc/issue\n```\n\nThis is fine too. We have the file's **content** as expected.\n\n```\n$ ls -la /etc/issue\n-rw-r--r-- 1 root root 26 Aug 12 17:48 /etc/issue\n```\n\nThis is also fine: it's the `/etc/issue` by default of the AMI, untouched in\nany way.\n\n## Stack \"with symlink mode\"\n\nNow, let's take the stack described in the `symlink-mode` tag of this\nrepository, with the following Metadata:\n\n```\nMetadata:\n  AWS::CloudFormation::Init:\n    config:\n      files:\n        \"/home/ubuntu/demo_link\":\n          content: \"/etc/issue\"\n          mode:   \"120000\"\n          owner:  \"ubuntu\"\n          group:  \"ubuntu\"\n```\n\nNote that the difference is only this :\n\n```\n$ git diff no-mode symlink-mode\ndiff --git a/cf-stack.yml b/cf-stack.yml\nindex d962676..367bd18 100644\n--- a/cf-stack.yml\n+++ b/cf-stack.yml\n@@ -72,5 +72,6 @@ Resources:\n           files:\n             \"/home/ubuntu/demo_link\":\n               content: \"/etc/issue\"\n+              mode:   \" 120000\"\n               owner:  \"ubuntu\"\n               group:  \"ubuntu\"\n```\n\nLet's take a look at what it produces.\n\n```\n$ ls -la /home/ubuntu/demo_link \nlrwxrwxrwx 1 ubuntu ubuntu 10 Dec 21 10:55 /home/ubuntu/demo_link -\u003e /etc/issue\n```\n\nOk, we're fine here, it created a symlink to the good file, as expected.\n\n```\n$ ls -la /etc/issue\n---------- 1 root root 26 Aug 12 17:48 /etc/issue\n```\n\nAnd here we go. It just set the **mode of the linked file**, `/etc/issue`, to\n`0000`. If we set the mode to \"120654\" it will set the `/etc/issue` mode to\n`0654` and so on.\n\n# What I expected\n\nFor me, the \"To create a symlink, specify 120000\" should be strictly respected.\n\nI don't expect something that create a link to a file to touch this file by any\nmean : when you do a simple `ln -s TARGET LINK_NAME`, `ln` will not touch\nanything on the `LINK_NAME` file since it's taken strictly as a link **name** :\nit's just a property of you link, that's why you can even create symlink to\nthings that don't exist.\n\n# How to reproduce it\n\nJust run the stack defined in `cf-stack.yml` with the following parameters :\n\n- VpcId\n- KeyPair\n- SubnetId\n- AZ\n\nThere are 2 tags on this repository :\n\n- `no-mode` on commit `ce10023e98d490de53ab4d8a27b7ae947b8ceb9b`\n- `symlink-mode` on commit `c373c95593d7cacd9ed0568dbd4324c7a89ad1c6`\n\nThey both provide the CloudFormation stack to test yourself what I just\nexplained (the problem is in the `symlink-mode` one).\n\nYou'll also find what is needed to spawn this stack from Ansible if you prefer,\nbut this problem is absolutely not related to Ansible whatsoever and can be\nreproduced by spawning this stack \"by hand\" on the CloudFormation web-UI.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhorgix%2Fcfn-init-symlink-bugreport","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhorgix%2Fcfn-init-symlink-bugreport","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhorgix%2Fcfn-init-symlink-bugreport/lists"}