Permission level for setting Log level without being root - mongodb

I have a user with the roles userAdminAnyDatabase and readWriteAnyDatabase. But this does not seem to be enough to set log level for my database. So what permissions do I need to set without having to make my user root?
This is the error I get:
[thread1] Error: setLogLevel failed:{
"ok" : 0,
"errmsg" : "not authorized on admin to execute command { setParameter: 1.0, logComponentVerbosity: { verbosity: 3.0 } }",
"code" : 13
}

TL;DR Before use administrative command you need select admin database:
use admin
Also you need hostManager role or permission setParameter for cluster resource.
Read more about administrative command, admin database and setParameter
setLogLevel use administrative command setParameter:
function (logLevel, component) {
componentNames = [];
if (typeof component === "string") {
componentNames = component.split(".");
} else if (component !== undefined) {
throw Error("setLogLevel component must be a string:" + tojson(component));
}
var vDoc = {verbosity: logLevel};
// nest vDoc
for (var key, obj; componentNames.length > 0;) {
obj = {};
key = componentNames.pop();
obj[key] = vDoc;
vDoc = obj;
}
var res = this.adminCommand({setParameter: 1, logComponentVerbosity: vDoc});
if (!res.ok)
throw _getErrorWithCode(res, "setLogLevel failed:" + tojson(res));
return res;
}

Related

How to specify HTTP authentication (user, password) when using an URL for libvirt_volume.source

I am trying to Provision VMs with Terraform.
i give the source image for the vm
here:
source = "http://10.1.1.160/Builds/14.7.1.10_0.39637/output/KVM/14.7.1.10_0.39637-disk1.qcow2"
but this site require a user name and a password.
where and how can i specify the credentials of this site in my tf file?
this is my main.tf file:
terraform {
required_providers {
libvirt = {
source = "dmacvicar/libvirt"
}
}
}
provider "libvirt" {
uri = "qemu:///system"
}
resource "libvirt_volume" "centos7-qcow2" {
name = "centos7.qcow2"
pool = "default"
source = "http://10.1.1.160/Builds/14.7.1.10_0.39637/output/KVM/14.7.1.10_0.39637-disk1.qcow2"
format = "qcow2"
}
# Define KVM domain to create
resource "libvirt_domain" "gw" {
name = "gw"
memory = "8192"
vcpu = 4
network_interface {
network_name = "default"
}
disk {
volume_id = "${libvirt_volume.centos7-qcow2.id}"
}
console {
type = "pty"
target_type = "serial"
target_port = "0"
}
graphics {
type = "spice"
listen_type = "address"
autoport = true
}
}
when i run terraform apply i got this error:
*Error while determining image type for http://10.1.1.160/Builds/14.7.1.10_0.39637/output/KVM/14.7.1.10_0.39637-disk1.qcow2: Can't retrieve partial header of resource to determine file type: http://10.1.1.160/Builds/14.7.1.10_0.39637/output/KVM/14.7.1.10_0.39637-disk1.qcow2 - 401 Authorization Required
with libvirt_volume.centos7-qcow2,
on main.tf line 13, in resource "libvirt_volume" "centos7-qcow2":
13: resource "libvirt_volume" "centos7-qcow2" {*
thanks for helping!
I just added the password and the user to the URL, like this:
http://user:password#host/path
:)

Why is mongodb atlas using 25 connections per 1 active client

I am currently connecting to mongodb atlas using the following code
exports.connectToMongoose = async() =>{
try{
const result = await mongoose.connect(process.env.mongodbURL,{
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex:true,
useFindAndModify:false
})
}
const connectionResult = await mongooseConnection.connectToMongoose();
Although I am the only one user logged In . I can see that mongodb atlas is using 25 connections from the 500 available. Why does each client uses 25 connections and does that mean the mongodb atlas can only handle 20 concurrent clients
db.serverStatus().connections This may be helpful to get the total connections from your clients to your server or primary node in your cluster
Are you sure thats from your one connection? Each Mongo server will have multiple connections from other servers in the cluster, such as Mongos, and Arbiters, as well as health checks and monitoring.
Found this a while back that gives a snapshot of the connections and the IPs they came from.. if this helps
db.currentOp(true).inprog.reduce((accumulator, connection) => {
ipaddress = connection.client ? connection.client.split(":")[0] : "Internal";
if(typeof accumulator[ipaddress] == "undefined"){
accumulator[ipaddress]= {"active":0, "inactive":0};
}
if(connection.active==true) {
accumulator[ipaddress]["active"] = (accumulator[ipaddress]["active"] || 0) + 1;
accumulator["ACTIVE"] = (accumulator["ACTIVE"] || 0 ) +1;
} else {
accumulator[ipaddress]["inactive"] = (accumulator[ipaddress]["inactive"] || 0) + 1;
accumulator["INACTIVE"] = (accumulator["INACTIVE"] || 0 ) +1;
}
accumulator["TOTAL_CONNECTION_COUNT"]++;
return accumulator;
},
{ TOTAL_CONNECTION_COUNT: 0 }
)

Error # Database Connection Initialization : Error: database name must be a string

i just try to connect mongodb. but it show
Error # Database Connection Initialization : Error: database name
must be a string
Following is code:
try {
mongoDb.connect("localhost:27017/sample");
var db = mongoDb
}
catch (err) {
console.log('Error # Database Connection Initialization : ' + err);
}
Please try this
// Initialize connection once
MongoClient.connect("mongodb://localhost:27017/sample", function(err, database) {
if(err) return console.error(err);
db = database;
// the Mongo driver recommends starting the server here because most apps *should* fail to start if they have no DB. If yours is the exception, move the server startup elsewhere.
});

NOAUTH Authentication required when connecting to Redis Sentinel with LettuceConnectionFactory

I am trying to connect to a Redis server using sentinel with password. I got RedisCommandExecutionException: NOAUTH Authentication required when calling redisTemplate.opsForValue().get("key")
Exception in thread "Thread-6" org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis on localhost:6379; nested exception is com.lambdaworks.redis.RedisCommandExecutionException: NOAUTH Authentication required.
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.createLettuceConnector(LettuceConnectionFactory.java:544)
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.initConnection(LettuceConnectionFactory.java:213)
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getSharedConnection(LettuceConnectionFactory.java:517)
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getConnection(LettuceConnectionFactory.java:189)
This is how I configured the connection factory:
RedisSentinelConfiguration sentinelConfiguration = new RedisSentinelConfiguration().master("mymaster").sentinel("localhost", 26379);
LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory(sentinelConfiguration);
lettuceConnectionFactory.setDatabase(1);
lettuceConnectionFactory.setPassword("foobared");
When I tried using JedisConnectionFactory, it works.
It looks like the password is not set when using LettuceConnectionFactory with sentinel.
I'm using spring-data-redis 1.7.2.
UPDATE:
I checked the code in DefaultLettucePool and saw that the password is not used in generating RedisURI when sentinelConfiguration is involved. When I modified the code as following, it works now.
DefaultLettucePool:
private RedisURI getRedisURI() {
if (isRedisSentinelAware()) {
return LettuceConverters.sentinelConfigurationToRedisURI(sentinelConfiguration, password, getDatabase());
}
return createSimpleHostRedisURI();
}
And in LettuceConverters:
public static RedisURI sentinelConfigurationToRedisURI(RedisSentinelConfiguration sentinelConfiguration, String password, int database) {
Assert.notNull(sentinelConfiguration, "RedisSentinelConfiguration is required");
Set<RedisNode> sentinels = sentinelConfiguration.getSentinels();
RedisURI.Builder builder = null;
for (RedisNode sentinel : sentinels) {
if (builder == null) {
builder = RedisURI.Builder.sentinel(sentinel.getHost(), sentinel.getPort(), sentinelConfiguration.getMaster()
.getName());
}
else {
builder.withSentinel(sentinel.getHost(), sentinel.getPort());
}
}
if (password != null) {
builder = builder.withPassword(password);
}
builder.withDatabase(database);
return builder.build();
}

grails 2.2.4 and grails-spring-security-facebook plugin with GPmongoDB 1.3.0GA

When i use grails spring security facebook plugin with MongoDB database, it keep throwing OptimisticLockingException on these section.
Then i override it with FacebookAuthService like these.
class FacebookAuthService {
def create(FacebookAuthToken token) {
FacebookUser fbUser = new FacebookUser(uid: token.uid)
fbUser.accessToken = token.accessToken?.accessToken
fbUser.accessTokenExpires = token.accessToken?.expireAt
Facebook facebook = new FacebookTemplate(token.accessToken.accessToken)
FacebookProfile fbProfile = facebook.userOperations().userProfile
User user = User.findByUsernameOrFacebookId(fbProfile.email,fbProfile.id)
if(!user){
user = new User()
user.facebookId = fbProfile.id
user.firstname = fbProfile.firstName.toLS()
user.lastname = fbProfile.lastName.toLS()
user.gender = Gender.strToEnum(fbProfile.gender)
user.acceptTerms = true
user.acceptTermsDate = new Date()
user.accountExpired = false
user.passwordExpired = false
user.accountLocked = false
user.enabled = true
user.username = "facebook_$token.uid"
user.password = token.accessToken.accessToken
}else{
user.facebookId = fbProfile.id
}
user.save(flush: true, failOnError: true)
fbUser.user = user
Role role = Role.findByAuthority('ROLE_USER')
if (role && !user.authorities.contains(role)) {
UserRole.create(user, role)
}
fbUser.save(flush: true, failOnError: true)
return fbUser
}
def getAppUser(FacebookUser facebookUser){
return facebookUser?.user
}
Collection<GrantedAuthority> getRoles(User user){
return UserRole.findAllByUser(user)?.role?.collect{ role ->
new GrantedAuthorityImpl(role.authority)
}
}
}
But now it throws Connection wait timeout after 120000 ms. Stacktrace follows:
Message: Connection wait timeout after 120000 ms
I know there is bug with GPMONGODB driver. and fixed it like described on there.
Please help me to fix it
Grails version 2.2.4
mongodb version 2.2.4
gpmongo driver version 1.3.0GA
spring security facebook plugin version :0.14.5
also it includes thse additional plugins to collect user information.
'org.springframework.social:spring-social-core:1.0.3.RELEASE'
'org.springframework.social:spring-social-facebook:1.0.3.RELEASE'
Edit:
I found out the cause
com.the6hours.grails.springsecurity.facebook.FacebookAuthProvider class's authenticate method keeps calling on every request. So what could be the cause of this loop ?