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

EmbeddedMongo on /tmp directory has not execution permission #422

Closed
filirnd opened this issue Sep 12, 2022 · 16 comments
Closed

EmbeddedMongo on /tmp directory has not execution permission #422

filirnd opened this issue Sep 12, 2022 · 16 comments
Assignees

Comments

@filirnd
Copy link

filirnd commented Sep 12, 2022

Hi I've an issue with mongo embedded. I've fedora 32 SO with kernel "Linux fedora-desktop 5.11.22-100.fc32.x86" set up this dependency on maven:

        <dependency>
            <groupId>de.flapdoodle.embed</groupId>
            <artifactId>de.flapdoodle.embed.mongo</artifactId>
            <version>3.4.8</version>
            <scope>test</scope>
        </dependency>`

And this is my test code:

import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoDatabase;
import de.flapdoodle.embed.mongo.MongodExecutable;
import de.flapdoodle.embed.mongo.MongodProcess;
import de.flapdoodle.embed.mongo.MongodStarter;
import de.flapdoodle.embed.mongo.config.MongodConfig;
import de.flapdoodle.embed.mongo.config.Net;
import de.flapdoodle.embed.mongo.distribution.Version;
import de.flapdoodle.embed.process.runtime.Network;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory;

import java.io.IOException;

public class EmbMongotest {
    public static void main(String[] args) throws IOException {
        MongodStarter starter = MongodStarter.getDefaultInstance();

        int port = Network.getFreeServerPort();
        MongodConfig mongodConfig = MongodConfig.builder()
                .version(Version.Main.PRODUCTION)
                .net(new Net(port, Network.localhostIsIPv6()))
                .build();

        MongodExecutable mongodExecutable = null;
        try {
            mongodExecutable = starter.prepare(mongodConfig);
            MongodProcess mongod = mongodExecutable.start();

            try (MongoClient mongo = MongoClients.create("mongodb://localhost:"+port)) {
                SimpleMongoClientDatabaseFactory factory = new SimpleMongoClientDatabaseFactory(mongo,"testDB");
                MongoDatabase db = mongo.getDatabase("testDB");
                MongoTemplate template = new MongoTemplate(factory);
                template.save(new TClass("variable"));
            } catch (Exception exception) {
                exception.printStackTrace();
            }
        } finally {
            if (mongodExecutable != null)
                mongodExecutable.stop();
        }
    }

    @Getter
    @Setter
    @AllArgsConstructor
    @NoArgsConstructor
    static class TClass {
        private String testVar;
    }
}

This is the issue that I encountered:

2022-09-12 09:48:16 fedora-desktop ERROR  AbstractProcess:116 - failed to call start()
java.io.IOException: Cannot run program "/tmp/extract-35fba5ae-5537-4e2a-8505-cf700f548460extractmongod": error=13, Permesso negato
	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1128)
	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1071)
	at de.flapdoodle.embed.process.runtime.ProcessControl.start(ProcessControl.java:165)
	at de.flapdoodle.embed.process.runtime.AbstractProcess.<init>(AbstractProcess.java:96)
	at de.flapdoodle.embed.mongo.AbstractMongoProcess.<init>(AbstractMongoProcess.java:53)
	at de.flapdoodle.embed.mongo.MongodProcess.<init>(MongodProcess.java:50)
	at de.flapdoodle.embed.mongo.MongodExecutable.start(MongodExecutable.java:44)
	at de.flapdoodle.embed.mongo.MongodExecutable.start(MongodExecutable.java:34)
	at de.flapdoodle.embed.process.runtime.Executable.start(Executable.java:109)
	at com.fw.EmbMongotest.main(EmbMongotest.java:39)
Caused by: java.io.IOException: error=13, Permesso negato
	at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)
	at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:340)
	at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:271)
	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1107)
	... 9 common frames omitted

I have tried to set system properties flapdoodle directory to another dir with all permission but it not works too.
Only if I launch the java application with root permission I can run this code without errors.

I have had this error since 1 month ago. Before the mongoembedded worked great.

@michaelmosmann
Copy link
Member

Can you try to run this executable in /tmp ? I would guess that your Linux distro disabled executables in /tmp. If you can copy this file to an other directory and execute it there than this is the cause..

@filirnd
Copy link
Author

filirnd commented Sep 15, 2022

No, I execute this code with the IntelliJ DI play button and the execution goes under my home.
The problem is the mongo embedded temporary file that was created (by flapdoodle ?) with wrong permissions.

@michaelmosmann
Copy link
Member

Hmm..you can try to create a breakpoint and inspect the file.. I would guess that the executable bit is set, but your Linux dist prohibits execution of anything located in /tmp

@muthenberg
Copy link

I am facing the same problem on a Mac.

@filirnd
Copy link
Author

filirnd commented Sep 15, 2022

I have tried to set system properties flapdoodle directory to another dir with all permission but it not works too.

As I wrote here I have tried to change the file directory to my home (with all permissions) and have the same results.
If I check the file on a breakpoint has these permissions -rw-r--r--
and /tmp has this permissions drwxrwxrwt
I think it is related to how the creator of the file sets the permissions

@michaelmosmann
Copy link
Member

Hmm.. this is strange as I did not change anything related to this..

@michaelmosmann
Copy link
Member

@michaelmosmann
Copy link
Member

@filirnd any progress with that?

@filirnd
Copy link
Author

filirnd commented Sep 28, 2022

@filirnd any progress with that?

Sorry, only today I can try this.
Have some problems with the code on the first comment. Maybe some classes changed.
I don't find this classes anymore
import de.flapdoodle.embed.mongo.MongodExecutable;
import de.flapdoodle.embed.mongo.MongodProcess;
import de.flapdoodle.embed.mongo.MongodStarter;
import de.flapdoodle.embed.mongo.config.MongodConfig;

@michaelmosmann
Copy link
Member

@filirnd If you dont use spring then you will find how to use it here: https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo/blob/embed-mongo-4.x/Howto.md

@filirnd
Copy link
Author

filirnd commented Sep 29, 2022

@filirnd If you dont use spring then you will find how to use it here: https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo/blob/embed-mongo-4.x/Howto.md

the first example works. Only for info, I received this log errors (but insert and find works great):

2022-09-29 12:18:59 fedora-desktop  WARN  LinuxPackageFinder:211 - because there is no package for PRODUCTION:Platform{operatingSystem=Linux, architecture=X86_64} we fall back to PRODUCTION:Platform{operatingSystem=Linux, architecture=X86_64, version=Ubuntu_20_04}
[mongod error]/home/fili/.embedmongo/fileSets/0eb568a806eaba39db7c7786cd674ca3a406f1de25f6401093a53fc73725b707/mongod: /lib64/libcurl.so.4: no version information available (required by /home/fili/.embedmongo/fileSets/0eb568a806eaba39db7c7786cd674ca3a406f1de25f6401093a53fc73725b707/mongod)
[mongod error] [mongod output]{"t":{"$date":"2022-09-29T12:19:00.266+02:00"},"s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"main","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}

@michaelmosmann
Copy link
Member

@filirnd .. hmmm.. thanks.. looks like mongod tries to download some version information stuff? strange..

@michaelmosmann
Copy link
Member

@filirnd
Copy link
Author

filirnd commented Sep 30, 2022

@filirnd found this: https://stackoverflow.com/questions/56942214/how-to-install-mongod-with-libcurl4

Thank you. However, is not a problem, now embedded mongo works great. Seems it uses the home folder now for temporary files.
I'm going to close the issue.
Thank you for your support.

@filirnd filirnd closed this as completed Sep 30, 2022
@michaelmosmann
Copy link
Member

@filirnd with the latest release i extract all binaries to some directory in home folder and checking the hash of the content to ensure that the right version is used .. so /tmp is not used for that anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants