Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong permissions when creating local files #2855

Closed
juan-carvajal opened this issue Oct 16, 2024 · 3 comments
Closed

Wrong permissions when creating local files #2855

juan-carvajal opened this issue Oct 16, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@juan-carvajal
Copy link

Bug Description

Hello! I believe I have found a bug.
This is my config:

{
  "target": {
    "path": "deploy/service",
    "namespace": "ns"
  },
  "feature": {
    "env": {
      "override": {
        "CONFIG_LOCATION": "config/config.evd.toml",
        "RESOURCES_LOCATION": "resources/environment",
        "DATASCIENCE_SECRET_LOCATION": ".env.service-secret",
        "MONGODB_HOST": "ds-model-management-mongodb"
      }
    },
    "fs": "localwithoverrides",
    "network": true
  },
  "kubeconfig": "~/.kube/config",
  "kube_context": "random-context",
  "agent": {
    "log_level": "debug",
    "json_log": false,
    "namespace": "ns",
    "image": "ghcr.io/metalbear-co/mirrord:latest",
    "image_pull_policy": "IfNotPresent",
    "image_pull_secrets": [],
    "ttl": 30,
    "ephemeral": false,
    "communication_timeout": 30,
    "startup_timeout": 360,
    "network_interface": "eth0",
    "flush_connections": false
  }
}

My service is creating a file like this (Go code):

func CopyFile(ctx context.Context, source string, targetFolder string, targetFileName string) (string, error) {
	logger := stlog.LoggerFromContext(ctx)
	_ = Mkdir(targetFolder)
	input, err := os.ReadFile(source)
	if err != nil {
		return "", err
	}

	target := path.Join(targetFolder, targetFileName)
	err = os.WriteFile(target, input, 0644)
	if err != nil {
		logger.ErrorContext(ctx, "Error creating file", slog.String("file", target), slog.Any("error", err))
		return "", err
	}
	return target, nil
}

Please notice the 0644 permission, this means r/w for owner, read for everyone else.
The file is indeed being created, but it appears to have wrong permission after this operation.
A few function calls later, my code attemps to read the file and get permission denied. I tried inspecting the file with cat, permission denied too.
After inspecting the file permissions with ls -l and stat:

juan-popos@pop-os:~/Projects/slb/mlops-model-management/SKLearnServer/1729115711548380409/workspace/code/.s2i$ ls -l
total 4
--w--w-r-T 1 juan-popos juan-popos 70 Oct 16 16:57 environment
juan-popos@pop-os:~/Projects/slb/mlops-model-management/SKLearnServer/1729115711548380409/workspace/code/.s2i$ sudo stat environment
[sudo] password for juan-popos: 
  File: environment
  Size: 70        	Blocks: 8          IO Block: 4096   regular file
Device: fc01h/64513d	Inode: 23869201    Links: 1
Access: (1224/--w--w-r-T)  Uid: ( 1000/juan-popos)   Gid: ( 1000/juan-popos)
Access: 2024-10-16 16:56:35.483446863 -0500
Modify: 2024-10-16 16:57:04.565891017 -0500
Change: 2024-10-16 16:57:04.565891017 -0500
 Birth: 2024-10-16 16:56:35.483446863 -0500

Final permission is 1224/--w--w-r-T:
image

Why is this file being created with wrong permission?

Steps to Reproduce

  1. Setup mirrord with localwithoverrides fs.
  2. Using Golang, create a file with os.WriteFile, use perm 0644.
  3. try to read the newly created file (you will get an error).
  4. Examine file permissions with ls -l or stat (you will need sudo for this one). The resulting permission will be 1224/--w--w-r-T. This behavior seems unexpected.

Backtrace

No response

mirrord layer logs

No response

Internal proxy logs

No response

Your operating system and version

Pop!_OS 22.04 LTS x86_64 (kernel 6.9.3-76060903-generic)

Local process

Go 1.22.7 linux/amd64

Local process version

Go 1.22.7 linux/amd64

Additional Info

No response

@juan-carvajal juan-carvajal added the bug Something isn't working label Oct 16, 2024
Copy link

linear bot commented Oct 16, 2024

@aviramha
Copy link
Member

Thanks for reporting!
Probably #2614

@aviramha
Copy link
Member

Closing in favor of #2614

@aviramha aviramha closed this as not planned Won't fix, can't repro, duplicate, stale Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants